[SGVLUG] [Sclug] Copying directory trees in WINDOWS (ugh!)
Emerson, Tom (*IC)
Tom.Emerson at wbconsultant.com
Mon Jan 25 12:15:53 PST 2010
> --- On Fri, 12/25/09, James E. Lang <jim at lang.hm> wrote:
>
> > From: James E. Lang <jim at lang.hm>
> > Subject: [Sclug] Copying directory trees in WINDOWS (ugh!)
> > How does one go about copying a whole
> > directory tree in Windows? I see no recursive option for the "copy"
> > command. Copy *.* f: only copies the files. Copy dir1\
> dir2\ does the
> > same. I can't lay my hands on a Linux live CD right now. It
> would be
> > easy that way! Windows is SO PRIMITIVE!
I know that DOS has a number of "recursive" options, usually /s does the trick, so I was surprised to hear the claim that copy didn't have the recursive option (perhaps it was dropped?) but, sure enough, per the latest version of DOS:
C:\Documents and Settings\xtemerso>copy /?
Copies one or more files to another location.
COPY [/D] [/V] [/N] [/Y | /-Y] [/Z] [/A | /B ] source [/A | /B]
[+ source [/A | /B] [+ ...]] [destination [/A | /B]]
source Specifies the file or files to be copied.
/A Indicates an ASCII text file.
/B Indicates a binary file.
/D Allow the destination file to be created decrypted
destination Specifies the directory and/or filename for the new file(s).
/V Verifies that new files are written correctly.
/N Uses short filename, if available, when copying a file with a
non-8dot3 name.
/Y Suppresses prompting to confirm you want to overwrite an
existing destination file.
/-Y Causes prompting to confirm you want to overwrite an
existing destination file.
/Z Copies networked files in restartable mode.
The switch /Y may be preset in the COPYCMD environment variable.
This may be overridden with /-Y on the command line. Default is
to prompt on overwrites unless COPY command is being executed from
within a batch script.
To append files, specify a single file for destination, but multiple files
for source (using wildcards or file1+file2+file3 format).
== nothing about recursion :(
That said, you might want to consider "services for unix", available from Microsoft
http://www.microsoft.com/downloads/details.aspx?FamilyID=896C9688-601B-44F1-81A4-02878FF11778
With that installed, you can use cp:
C:\Documents and Settings\xtemerso>cp -?
cp: illegal option '?'
usage: cp [-Rr] [-fip] src target
cp [-Rr] [-fip] src1 ... srcN directory
C:\Documents and Settings\xtemerso>which cp
C:\SFU\common\cp.exe
C:\Documents and Settings\xtemerso>cd \sfu
C:\SFU>cd bin
C:\SFU\bin>ls
[ clear expand ipcrm more psxoffset ssimda tzselect
addr cmp expr ipcs mpack pwd strerror umask
alias col false ispell mt ranlib strings unalias
ar column fc jobs munpack rcp strip uname
at comm fg join mv rdist strsignal unexpand
atq command fgrep kill mvwtmpx rdistd stty unifdef
atrm cp file ksh newgrp read su uniq
awk cpio fileinfo last nice regpwd sum unixpath2win
banner crontab fileinfo.exe less nl renice syslogd unvis
basename csh find lessecho nm reset tail uudecode
batch csplit finger lesskey nohup rlogin talk uuencode
bc ctags flip lex nslookup rm tar vi
bg cut fmt line nsupdate rmdir tcsh view
bp date fold ln ntpath2posix rpcgen tee vis
c89 dc ftp locale nvi rpcinfo telnet wait
cal dd gencat localedef od rsh test wc
calendar df getconf logger passwd rstartd tftp who
captoinfo diff getopt login paste runwin32 tic whoami
cat diff3 getopts loginenv patch script time winpath2unix
cat32 dig grep logname pathchk sdiff tip wvisible
cat32.exe dircmp head lp pax sed toe xargs
cc dirname hexdump ls pdomain service touch yacc
cd dnsquery host m4 pg sh tput yearistype
chgpath du hostname mail ping showmount tr
chgrp echo iconv mailx posixpath2nt size true
chmod ed id make pr sleep truss
chown egrep infocmp man printf sort tset
chsh env infotocap mkdir ps spell tsort
cksum ex install mkfifo pstat split tty
C:\SFU\bin>man cp
cp(1) cp(1)
cp
NAME
cp - copy files
SYNOPSIS
cp [-Rr] [-fip] src target
cp [-Rr] [-fip] src1 ... srcN directory
DESCRIPTION
In the first synopsis form, the cp(1) utility copies the contents of the
source_file to the target_file. In the second, third, and fourth synopsis
forms, the contents of each named source_file are copied to the
destination target_directory. The names of the files are not changed. If
cp(1) detects an attempt to copy a file to itself, the copy will fail.
OPTIONS
-f
For each existing destination path name, remove it and create a new
file, without prompting for confirmation regardless of its
permissions.
-i
Inquire before copying a file that would overwrite an existing file.
The cp(1) utility writes a prompt to the standard error output. If the
response from the standard input begins with the character "y," the
file copy is attempted.
-p
Preserve in the copy the following attributes, as permissions allow:
Modification time
Access time
File flags
File mode
User ID
Group ID
The following also apply to this option:
* If the user ID and group ID cannot be preserved, no error
message is displayed and the exit value is not altered.
* If the source file has its set user ID bit on, and the user ID
cannot be preserved, the set user ID bit is not preserved in the
copy's permissions.
* If the source file has its set group ID bit on and the group ID
cannot be preserved, the set group ID bit is not preserved in
the copy's permissions.
* If the source file has both its set user ID and set group ID
bits on, and either the user ID or group ID cannot be preserved,
neither the set user ID nor set group ID bits are preserved in
the copy's permissions.
-R
Copy file hierarchies, including FIFOs; this may not be specified with
the -r option.
-r
Copy file hierarchies but not including special files such as FIFOs;
this may not be specified with the -R option.
The contents of each destination file that already exists are overwritten
if permissions allow, but its mode, user ID, and group ID are unchanged.
In the second synopsis form, target_directory must exist unless there is
only one named source_file, which is a directory, and the -R flag is
specified.
If the destination file does not exist, the mode of the source file is
used as modified by the file-mode creation mask.
Appropriate permissions are required for file creation or overwriting.
DIAGNOSTICS
The cp(1) utility exits 0 on success, >0 if an error occurred.
SEE ALSO
/usr/share/man/cat1/cp.1 line 82/87 (98%)
mv(1)e/man/cat1/cp.1 line 83/87 (98%)
umask(1)
More information about the SGVLUG
mailing list