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

DESCRIPTION

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

EXAMPLES

50       Read a file twice:
51
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 eq $data2 if the file wasn't updated
58
59       Read the last 10 bytes from a file:
60
61              set f [open file.data]
62              # This is guaranteed to work with binary data but
63              # may fail with other encodings...
64              fconfigure $f -translation binary
65              seek $f -10 end
66              set data [read $f 10]
67              close $f
68

SEE ALSO

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

KEYWORDS

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