Install Perl 5.8.8
[msysgit.git] / mingw / html / lib / File / Copy.html
blob8e4729174399c22afead11dfe5004221f2d979b8
1 <?xml version="1.0" ?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5 <title>File::Copy - Copy files or filehandles</title>
6 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
7 <link rev="made" href="mailto:" />
8 </head>
10 <body style="background-color: white">
11 <table border="0" width="100%" cellspacing="0" cellpadding="3">
12 <tr><td class="block" style="background-color: #cccccc" valign="middle">
13 <big><strong><span class="block">&nbsp;File::Copy - Copy files or filehandles</span></strong></big>
14 </td></tr>
15 </table>
17 <p><a name="__index__"></a></p>
18 <!-- INDEX BEGIN -->
20 <ul>
22 <li><a href="#name">NAME</a></li>
23 <li><a href="#synopsis">SYNOPSIS</a></li>
24 <li><a href="#description">DESCRIPTION</a></li>
25 <ul>
27 <li><a href="#special_behaviour_if_syscopy_is_defined__os_2__vms_and_win32_">Special behaviour if <code>syscopy</code> is defined (OS/2, VMS and Win32)</a></li>
28 </ul>
30 <li><a href="#return">RETURN</a></li>
31 <li><a href="#notes">NOTES</a></li>
32 <li><a href="#author">AUTHOR</a></li>
33 </ul>
34 <!-- INDEX END -->
36 <hr />
37 <p>
38 </p>
39 <h1><a name="name">NAME</a></h1>
40 <p>File::Copy - Copy files or filehandles</p>
41 <p>
42 </p>
43 <hr />
44 <h1><a name="synopsis">SYNOPSIS</a></h1>
45 <pre>
46 use File::Copy;</pre>
47 <pre>
48 copy(&quot;file1&quot;,&quot;file2&quot;) or die &quot;Copy failed: $!&quot;;
49 copy(&quot;Copy.pm&quot;,\*STDOUT);
50 move(&quot;/dev1/fileA&quot;,&quot;/dev2/fileB&quot;);</pre>
51 <pre>
52 use File::Copy &quot;cp&quot;;</pre>
53 <pre>
54 $n = FileHandle-&gt;new(&quot;/a/file&quot;,&quot;r&quot;);
55 cp($n,&quot;x&quot;);</pre>
56 <p>
57 </p>
58 <hr />
59 <h1><a name="description">DESCRIPTION</a></h1>
60 <p>The File::Copy module provides two basic functions, <code>copy</code> and
61 <code>move</code>, which are useful for getting the contents of a file from
62 one place to another.</p>
63 <ul>
64 <li>
65 <p>The <code>copy</code> function takes two
66 parameters: a file to copy from and a file to copy to. Either
67 argument may be a string, a FileHandle reference or a FileHandle
68 glob. Obviously, if the first argument is a filehandle of some
69 sort, it will be read from, and if it is a file <em>name</em> it will
70 be opened for reading. Likewise, the second argument will be
71 written to (and created if need be). Trying to copy a file on top
72 of itself is a fatal error.</p>
73 <p><strong>Note that passing in
74 files as handles instead of names may lead to loss of information
75 on some operating systems; it is recommended that you use file
76 names whenever possible.</strong> Files are opened in binary mode where
77 applicable. To get a consistent behaviour when copying from a
78 filehandle to a file, use <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_binmode"><code>binmode</code></a> on the filehandle.</p>
79 <p>An optional third parameter can be used to specify the buffer
80 size used for copying. This is the number of bytes from the
81 first file, that wil be held in memory at any given time, before
82 being written to the second file. The default buffer size depends
83 upon the file, but will generally be the whole file (up to 2Mb), or
84 1k for filehandles that do not reference files (eg. sockets).</p>
85 <p>You may use the syntax <code>use File::Copy &quot;cp&quot;</code> to get at the
86 ``cp'' alias for this function. The syntax is <em>exactly</em> the same.</p>
87 </li>
88 <li>
89 <p>The <code>move</code> function also takes two parameters: the current name
90 and the intended name of the file to be moved. If the destination
91 already exists and is a directory, and the source is not a
92 directory, then the source file will be renamed into the directory
93 specified by the destination.</p>
94 <p>If possible, <code>move()</code> will simply rename the file. Otherwise, it copies
95 the file to the new location and deletes the original. If an error occurs
96 during this copy-and-delete process, you may be left with a (possibly partial)
97 copy of the file under the destination name.</p>
98 <p>You may use the ``mv'' alias for this function in the same way that
99 you may use the ``cp'' alias for <code>copy</code>.</p>
100 </li>
101 </ul>
102 <p>File::Copy also provides the <code>syscopy</code> routine, which copies the
103 file specified in the first parameter to the file specified in the
104 second parameter, preserving OS-specific attributes and file
105 structure. For Unix systems, this is equivalent to the simple
106 <code>copy</code> routine, which doesn't preserve OS-specific attributes. For
107 VMS systems, this calls the <a href="#item_rmscopy"><code>rmscopy</code></a> routine (see below). For OS/2
108 systems, this calls the <code>syscopy</code> XSUB directly. For Win32 systems,
109 this calls <code>Win32::CopyFile</code>.</p>
110 <p>On Mac OS (Classic), <code>syscopy</code> calls <code>Mac::MoreFiles::FSpFileCopy</code>,
111 if available.</p>
113 </p>
114 <h2><a name="special_behaviour_if_syscopy_is_defined__os_2__vms_and_win32_">Special behaviour if <code>syscopy</code> is defined (OS/2, VMS and Win32)</a></h2>
115 <p>If both arguments to <code>copy</code> are not file handles,
116 then <code>copy</code> will perform a ``system copy'' of
117 the input file to a new output file, in order to preserve file
118 attributes, indexed file structure, <em>etc.</em> The buffer size
119 parameter is ignored. If either argument to <code>copy</code> is a
120 handle to an opened file, then data is copied using Perl
121 operators, and no effort is made to preserve file attributes
122 or record structure.</p>
123 <p>The system copy routine may also be called directly under VMS and OS/2
124 as <code>File::Copy::syscopy</code> (or under VMS as <code>File::Copy::rmscopy</code>, which
125 is the routine that does the actual work for syscopy).</p>
126 <dl>
127 <dt><strong><a name="item_rmscopy"><code>rmscopy($from,$to[,$date_flag])</code></a></strong>
129 <dd>
130 <p>The first and second arguments may be strings, typeglobs, typeglob
131 references, or objects inheriting from IO::Handle;
132 they are used in all cases to obtain the
133 <em>filespec</em> of the input and output files, respectively. The
134 name and type of the input file are used as defaults for the
135 output file, if necessary.</p>
136 </dd>
137 <dd>
138 <p>A new version of the output file is always created, which
139 inherits the structure and RMS attributes of the input file,
140 except for owner and protections (and possibly timestamps;
141 see below). All data from the input file is copied to the
142 output file; if either of the first two parameters to <a href="#item_rmscopy"><code>rmscopy</code></a>
143 is a file handle, its position is unchanged. (Note that this
144 means a file handle pointing to the output file will be
145 associated with an old version of that file after <a href="#item_rmscopy"><code>rmscopy</code></a>
146 returns, not the newly created version.)</p>
147 </dd>
148 <dd>
149 <p>The third parameter is an integer flag, which tells <a href="#item_rmscopy"><code>rmscopy</code></a>
150 how to handle timestamps. If it is &lt; 0, none of the input file's
151 timestamps are propagated to the output file. If it is &gt; 0, then
152 it is interpreted as a bitmask: if bit 0 (the LSB) is set, then
153 timestamps other than the revision date are propagated; if bit 1
154 is set, the revision date is propagated. If the third parameter
155 to <a href="#item_rmscopy"><code>rmscopy</code></a> is 0, then it behaves much like the DCL COPY command:
156 if the name or type of the output file was explicitly specified,
157 then no timestamps are propagated, but if they were taken implicitly
158 from the input filespec, then all timestamps other than the
159 revision date are propagated. If this parameter is not supplied,
160 it defaults to 0.</p>
161 </dd>
162 <dd>
163 <p>Like <code>copy</code>, <a href="#item_rmscopy"><code>rmscopy</code></a> returns 1 on success. If an error occurs,
164 it sets <a href="file://C|\msysgit\mingw\html/pod/perlvar.html#item___"><code>$!</code></a>, deletes the output file, and returns 0.</p>
165 </dd>
166 </li>
167 </dl>
169 </p>
170 <hr />
171 <h1><a name="return">RETURN</a></h1>
172 <p>All functions return 1 on success, 0 on failure.
173 $! will be set if an error was encountered.</p>
175 </p>
176 <hr />
177 <h1><a name="notes">NOTES</a></h1>
178 <ul>
179 <li>
180 <p>On Mac OS (Classic), the path separator is ':', not '/', and the
181 current directory is denoted as ':', not '.'. You should be careful
182 about specifying relative pathnames. While a full path always begins
183 with a volume name, a relative pathname should always begin with a
184 ':'. If specifying a volume name only, a trailing ':' is required.</p>
185 <p>E.g.</p>
186 <pre>
187 copy(&quot;file1&quot;, &quot;tmp&quot;); # creates the file 'tmp' in the current directory
188 copy(&quot;file1&quot;, &quot;:tmp:&quot;); # creates :tmp:file1
189 copy(&quot;file1&quot;, &quot;:tmp&quot;); # same as above
190 copy(&quot;file1&quot;, &quot;tmp&quot;); # same as above, if 'tmp' is a directory (but don't do
191 # that, since it may cause confusion, see example #1)
192 copy(&quot;file1&quot;, &quot;tmp:file1&quot;); # error, since 'tmp:' is not a volume
193 copy(&quot;file1&quot;, &quot;:tmp:file1&quot;); # ok, partial path
194 copy(&quot;file1&quot;, &quot;DataHD:&quot;); # creates DataHD:file1
196 move(&quot;MacintoshHD:fileA&quot;, &quot;DataHD:fileB&quot;); # moves (don't copies) files from one
197 # volume to another</pre>
198 </li>
199 </ul>
201 </p>
202 <hr />
203 <h1><a name="author">AUTHOR</a></h1>
204 <p>File::Copy was written by Aaron Sherman <em>&lt;<a href="mailto:ajs@ajs.com">ajs@ajs.com</a>&gt;</em> in 1995,
205 and updated by Charles Bailey <em>&lt;<a href="mailto:bailey@newman.upenn.edu">bailey@newman.upenn.edu</a>&gt;</em> in 1996.</p>
206 <table border="0" width="100%" cellspacing="0" cellpadding="3">
207 <tr><td class="block" style="background-color: #cccccc" valign="middle">
208 <big><strong><span class="block">&nbsp;File::Copy - Copy files or filehandles</span></strong></big>
209 </td></tr>
210 </table>
212 </body>
214 </html>