1seek(n)                      Tcl Built-In Commands                     seek(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       seek - Change the access position for an open channel
9

SYNOPSIS

11       seek channelId offset ?origin?
12_________________________________________________________________
13
14

DESCRIPTION

16       Changes the current access position for channelId.
17
18       ChannelId must be an identifier for an open channel such as a Tcl stan‐ │
19       dard channel (stdin, stdout, or stderr), the return value from an invo‐ │
20       cation  of  open or socket, or the result of a channel creation command │
21       provided by a Tcl extension.
22
23       The offset and origin arguments specify the position at which the  next
24       read  or  write  will  occur  for  channelId. Offset must be an integer
25       (which may be negative) and origin must be one of the following:
26
27       start     The new access position will be offset bytes from  the  start
28                 of the underlying file or device.
29
30       current   The new access position will be offset bytes from the current
31                 access position; a negative offset moves the access  position
32                 backwards in the underlying file or device.
33
34       end       The  new access position will be offset bytes from the end of
35                 the file or device.  A  negative  offset  places  the  access
36                 position before the end of file, and a positive offset places
37                 the access position after the end of file.
38
39       The origin argument defaults to start.
40
41       The command flushes all buffered output for the channel before the com‐
42       mand returns, even if the channel is in nonblocking mode.  It also dis‐
43       cards any buffered and unread input.  This  command  returns  an  empty
44       string.   An  error occurs if this command is applied to channels whose
45       underlying file or device does not support seeking.
46
47       Note that offset values are byte offsets, not character offsets.   Both │
48       seek and tell operate in terms of bytes, not characters, unlike read.
49

EXAMPLES

51       Read a file twice:
52              set f [open file.txt]
53              set data1 [read $f]
54              seek $f 0
55              set data2 [read $f]
56              close $f
57              # $data1 == $data2 if the file wasn't updated
58
59       Read the last 10 bytes from a file:
60              set f [open file.data]
61              # This is guaranteed to work with binary data but
62              # may fail with other encodings...
63              fconfigure $f -translation binary
64              seek $f -10 end
65              set data [read $f 10]
66              close $f
67
68

SEE ALSO

70       file(n), open(n), close(n), gets(n), tell(n), Tcl_StandardChannels(3)
71
72

KEYWORDS

74       access position, file, seek
75
76
77
78Tcl                                   8.1                              seek(n)
Impressum