1File::NCopy(3) User Contributed Perl Documentation File::NCopy(3)
2
3
4
6 File::NCopy - Deprecated module. Use File::Copy::Recursive instead.
7 Copy file, file. Copy file[s] | dir[s], dir
8
10 use File::NCopy qw(copy);
11
12 copy "file","other_file";
13 copy "file1","file2","file3","directory";
14
15 # we want to copy the directory recursively
16 copy \1,"directory1","directory2";
17 copy \1,"file1","file2","directory1","file3","directory2","file4",
18 "directory";
19
20 # can also use references to file handles, this is for backward
21 # compatibility with File::Copy
22 copy \*FILE1,\*FILE2;
23 copy \*FILE1,"file";
24 copy "file1",\*FILE2;
25
26
27 # we don't specify \1 as the first argument because we don't want to
28 # copy directories recursively
29 copy "*.c","*.pl","programs";
30 copy "*", "backup";
31
32 use File::NCopy;
33
34 # the below are the default config values
35 $file = File::NCopy->new(
36 'recursive' => 0,
37 'preserve' => 0,
38 'follow_links' => 0,
39 'force_write' => 0,
40 'set_permission' => \&File::NCopy::u_chmod,
41 'file_check' => \&File::NCopy::f_check,
42 'set_times' => \&File::NCopy::s_times,
43 );
44
45 set_permission will take two file names, the original to get the
46 file permissions from and the new file to set the file permissions
47 for.
48
49 file_check takes two parameters, the file names to check the file to
50 copy from and the file to copy to. I am using flock for Unix
51 systems.
52 Default for this is \&File::NCopy::f_check. On Unix you can also use
53 \&File::NCopy::unix_check. This one compares the inode and device
54 numbers.
55
56 set_times is used if the preserve attribute is true. It preserves
57 the access and modification time of the file and also attempts to
58 set the owner of the file to the original owner. This can be useful
59 in a script used by root, though enyone can preserve the access and
60 modification times. This also takes two arguments. The file to get
61 the stats from and apply the stats to.
62
63 On Unix boxes you shouldn't need to worry. On other system you may
64 want to supply your own sub references.
65
66 $file = File::NCopy->new(recursive => 1);
67 $file->copy "file","other_file";
68 $file->copy "directory1","directory2";
69
70 $file = File::NCopy->new(u_chmod => \&my_chmod,f_check => \&my_fcheck);
71 $file->copy "directory1","directory2";
72
74 File::NCopy::copy copies files to directories, or a single file to
75 another file. You can also use a reference to a file handle if you
76 wish whem doing a file to file copy. The functionality is very similar
77 to cp. If the argument is a directory to directory copy and the
78 recursive flag is set then it is done recursively like cp -R. In fact
79 it behaves like cp on Unix for the most part. If called in array
80 context, an array of successful copies is returned, otherwise the
81 number of succesful copies is returned. If passed a file handle, it's
82 difficult to make sure the file we are copying isn't the same that we
83 are copying to, since by opening the file in write mode it gets
84 pooched. To avoid this use file names instead, if at all possible,
85 especially for the to file. If passed a file handle, it is not closed
86 when copy returns, files opened by copy are closed.
87
88 copy
89 Copies a file to another file. Or a file to a directory. Or
90 multiple files and directories to another directory. Or a
91 directory to another directory. Wildcard arguments are expanded,
92 except for the last argument which should not be expanded. The
93 file and directory permissions are set to the orginating file's
94 permissions and if preserve is set the access and modification
95 times are also set. If preserve is set then the uid and gid will
96 also be attempted to be set, though this may only for for the men
97 in white hats. In list context it returns all the names of the
98 files/directories that were successfully copied. In scalar context
99 it returns the number of successful copies made. A directory
100 argument is considerd a single successful copy if it manages to
101 copy anything at all. To make a directory to directory copy the
102 recursive flag must be set.
103
104 cp Just calls copy. It's there to be compatible with File::Copy.
105
106 new If used then you can treat this as an object oriented module with
107 some configuration abilities.
108
109 recursive
110 If used as an object then you can use this to set the recursive
111 attribute. It can also be set when instantiating with new. The
112 other attributes must all be set when instantiating the object. If
113 it isn't specified then directories are not followed.
114
115 preserve
116 Attempt to preserve the last modification and access time as well
117 as user and group id's. This is a useful feature for sysadmins,
118 though the access and modification time should always be
119 preservable, the uid and gid may not.
120
121 follow_links
122 If the link is to a directory and this attribute is true then the
123 directory is followed and recursively copied. Otherwise a link is
124 made to the root directory the link points to. eg.
125
126 /sys/ is a link to /usr/src/sys/ is a link to /usr/src/i386/sys
127 then the link /sys/ is actually created in the source directory as
128 a link to /usr/src/i386/sys/ rather than /usr/src/sys/ since if the
129 link /usr/src/sys/ is removed then we lost the link even though the
130 directory we originally intended to link to still exists.
131
132 force_write
133 Force the writing of a file even if the permissions are read only
134 on it.
135
137 See SYNOPSIS.
138
140 When following links the target directory might not exactly the same as
141 the source directory. The reason is that we have to make sure we don't
142 follow circular or dead links. This is really a feature though the
143 result may not quite resemble the source dir, the overall content will
144 be the same. :)
145
146 From Ken Healy (Version 0.34)
147
148 On Win32, The use of backslash for paths is required.
149
151 Gabor Egressy gabor AT vmunix.com
152
153 Copyright (c) 1998 Gabor Egressy. All rights reserved. All wrongs
154 reversed. This program is free software; you can redistribute and/or
155 modify it under the same terms as Perl itself.
156
157 Some ideas gleaned from File::Copy by Aaron Sherman & Charles Bailey,
158 but the code was written from scratch.
159
160 Patch at versions 0.33, and 0.34 added by MZSANFORD.
161
162 0.35, 0.36 - Alexandr Ciornii (alexchorny AT gmail.com)
163
164
165
166perl v5.34.0 2021-07-22 File::NCopy(3)