PDA

View Full Version : DOS or XCOPY experts wanted



FoxyMX
08-03-2009, 01:32 PM
Here's a challenge for the DOS and XCOPY experts. :thumbs:

For some reason my XCOPY commands are no longer working properly. They will copy sometimes but not others, mostly not others, and I am completely mystified as to why.

This one just did the bizzo, copying all the folders and files to a new folder PHOTOs:

xcopy H:\PHOTOS\*.* M:\PHOTOS\*.* /y/d/s

BUT when I added a new folder it wouldn't copy it. When I added a file to that folder it then did copy it.

Also, if I change the command to the following...

xcopy D:\Canon\*.* H:\Canon\*.* /y/d/s

... it won't work. Nothing gets copied, even though there are many new folders and files that should be copied.

This is all very strange behaviour as it used to work fine. Anyone have any idea why? No updates have been applied recently.

Blam
08-03-2009, 01:49 PM
Why don't you just use something like syncback?

BTW jwil may be able to help you with this, I've read a bit about it on his blog.

The problem you have is quite baffling indeed though

jwil1
08-03-2009, 02:00 PM
/S is your problem. Use /E instead :)

/S excludes empty directories, while /E copies empty ones as well.

FoxyMX
08-03-2009, 03:06 PM
/S is your problem. Use /E instead :)

/S excludes empty directories, while /E copies empty ones as well.

Well, I learnt something today! :thumbs:

Those /y/d/s commands always were a bit of a mystery to me. I just used them because that's what Godfather uses. :p

However, it hasn't fixed my problem. :(

Since starting this thread I tried leaving out the /y/d/s bits and it still doesn't do the job. The following line will copy my Eudora folder only and nothing else, even though there are other folders with files that should be copied:

xcopy d:\Documents\*.* h:\Documents\*.* /y/d/e

I am becoming convinced that there is something wrong with my folders somehow. Does it matter if the folders and files are Read Only? I am sure some files have always been Read Only and still copied over.

HAL9000
08-03-2009, 03:10 PM
You should look at robocopy. Replacement for XCOPY that handles long file names and offers additional functions such as logging and archiving.

jwil1
08-03-2009, 04:54 PM
Try taking out the *.*, putting "" around the D:\Documents and H:\Documents. Also have a look at my blog http://g33kblog.wordpress.com to see if my version works any better :)

sroby
09-03-2009, 10:56 AM
Theres a know bug in xcopy (xcopy32?) where it will SOMETIMES simply stops/crashes out of the copy without warning(especially if theres alot of files/nested sub-dirs). Ive seen it a few times.
Use xxcopy instead.

jwil1
09-03-2009, 11:50 AM
Theres a know bug in xcopy (xcopy32?) where it will SOMETIMES simply stops/crashes out of the copy without warning(especially if theres alot of files/nested sub-dirs). Ive seen it a few times.
Use xxcopy instead.

That happened to me - I think having too large a folder to copy from makes it crash?

I made it look at folders one level down and it was fine.

ManUFan
09-03-2009, 12:41 PM
In case you don't know....

To see what a DOS command does (including switches) you only need to open a command window (Windows Key + R - then type CMD or COMMAND followed by ENTER, type EXIT to close the command window) and type the command followed by "/?" excluding the quotes:

e.g. for xcopy - type "xcopy /?" (excl quotes).

This is the result:

Copies files and directory trees.

XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W]
[/C] [/I] [/Q] [/F] [/L] [/G] [/H] [/R] [/T] [/U]
[/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z]
[/EXCLUDE:file1[+file2][+file3]...]

source Specifies the file(s) to copy.
destination Specifies the location and/or name of new files.
/A Copies only files with the archive attribute set,
doesn't change the attribute.
/M Copies only files with the archive attribute set,
turns off the archive attribute.
/D:m-d-y Copies files changed on or after the specified date.
If no date is given, copies only those files whose
source time is newer than the destination time.
/EXCLUDE:file1[+file2][+file3]...
Specifies a list of files containing strings. Each string
should be in a separate line in the files. When any of the
strings match any part of the absolute path of the file to be
copied, that file will be excluded from being copied. For
example, specifying a string like \obj\ or .obj will exclude
all files underneath the directory obj or all files with the
.obj extension respectively.
/P Prompts you before creating each destination file.
/S Copies directories and subdirectories except empty ones.
/E Copies directories and subdirectories, including empty ones.
Same as /S /E. May be used to modify /T.
/V Verifies each new file.
/W Prompts you to press a key before copying.
/C Continues copying even if errors occur.
/I If destination does not exist and copying more than one file,
assumes that destination must be a directory.
/Q Does not display file names while copying.
/F Displays full source and destination file names while copying.
/L Displays files that would be copied.
/G Allows the copying of encrypted files to destination that does
not support encryption.
/H Copies hidden and system files also.
/R Overwrites read-only files.
/T Creates directory structure, but does not copy files. Does not
include empty directories or subdirectories. /T /E includes
empty directories and subdirectories.
/U Copies only files that already exist in destination.
/K Copies attributes. Normal Xcopy will reset read-only attributes.
/N Copies using the generated short names.
/O Copies file ownership and ACL information.
/X Copies file audit settings (implies /O).
/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.


BTW: to get a list of available DOS commands type "HELP" at the prompt in the command window. Remember to be careful! some commands can 'hurt' your system - e.g. FORMAT.

Chilling_Silence
09-03-2009, 03:02 PM
Hey wow SyncBack Free looks useful!!

Rob99
09-03-2009, 03:22 PM
Hey wow SyncBack Free looks useful!!Used it a while ago, cant remember why I stopped using it, but it would have been a good reason ..

FoxyMX
10-03-2009, 11:17 AM
Try taking out the *.*, putting "" around the D:\Documents and H:\Documents. Also have a look at my blog http://g33kblog.wordpress.com to see if my version works any better :)

Removing the *.* made no difference, it still wouldn't work. Admittedly some of the folders did contain a lot of files but even after moving a lot out it wasn't happy.

I also had a look at your blog but have to say that it fried my brain somewhat trying to figure it all out. :blush:

Anyway, I tried xxcopy and that appears to be working. Haven't had enough files change in the past few days to know for sure but at least it is doing things that xcopy refused to do. :thumbs:

Will look at the other suggestions when I have time but for now my files appear to be getting backed up to the other drive when they are supposed to.

Many thanks for all the help and suggestions. :cool:

ubergeek85
10-03-2009, 11:31 AM
Quotes are a good idea if the path has spaces in it.

Also, /d can't be helping.

And I was under the impression that you needed to put spaces between switches, ie: command /a /d /c. Am I mistaken?

Chilling_Silence
10-03-2009, 11:40 AM
I setup a mate with SyncBack Free last night, heaps good! Compresses each file as a .zip which was kinda weird but the easy restore options pretty cool!!

I used to use xcopy myself except IIRC I had about 9-10 arguements rather than just 3. I'll try and get a customer to email me the batch script I wrote them and I'll post it up here :)

FoxyMX
10-03-2009, 12:00 PM
Quotes are a good idea if the path has spaces in it.

Also, /d can't be helping.

And I was under the impression that you needed to put spaces between switches, ie: command /a /d /c. Am I mistaken?

Always have put quotes around paths that have spaces in them.

Why would /d not be helping? That is to copy changed files.

It appears to make no difference whether spaces are put between switches or not.

Gobe1
10-03-2009, 01:34 PM
I use xcopy and xxcopy all the time:wub

my bat file is just xcopy z:\* e:\ /e/c

or xxcopy z:\* e:\ /e/c

Tried Robocopy on vista but xcopy worked just as well
Never had trouble except too long file names

EDIT But i did have trouble from linux permissions

Chilling_Silence
10-03-2009, 01:36 PM
Here's one that Ive been using successfully for the last year or so (Variations in folder location, but yeah ..)


@ECHO OFF
echo Please run the CMT backup first and then exit Outlook while the backup occurs
echo You need to ensure your cellphone has been unplugged as well, as it tries to re-open Outlook
echo .
echo Once this has been done, then you may proceed
echo .
echo This should always take longer than 30 seconds -- If it doesnt then something is wrong
pause
@ECHO ON
xcopy "c:\CMTBack\*.zip" E:\Backups\CMTBack\*.* /E /V /C /I /F /G /H /R /K /Y /Z /D
xcopy "c:\Data\Outlook" E:\Backups\Outlook /E /V /C /I /F /G /H /R /K /Y /Z /D
xcopy "C:\Documents and Settings\Administrator\Local Settings\Application Data\Microsoft\Outlook\archive.pst" E:\Backups\Outlook\archive.pst /E /V /C /I /F /G /H /R /K /Y /Z /D
xcopy "c:\Data\Documents\Clients" E:\Backups\Clients /E /V /C /I /F /G /H /R /K /Y /Z /D
xcopy "c:\Data\Documents\Job Sheets" E:\Backups\JobSheets /E /V /C /I /F /G /H /R /K /Y /Z /D
xcopy "c:\Data\Documents\Business" E:\Backups\Business /E /V /C /I /F /G /H /R /K /Y /Z /D
xcopy "c:\Data\Documents\Business development" E:\Backups\BusinessDevelopment /E /V /C /I /F /G /H /R /K /Y /Z /D
xcopy "c:\Data\Documents\B Report" E:\Backups\BReport /E /V /C /I /F /G /H /R /K /Y /Z /D
xcopy "c:\Data\Documents\Business development projects" E:\Backups\BusinessDevelopmentProjects /E /V /C /I /F /G /H /R /K /Y /Z /D
xcopy "c:\Data\Documents\Goals & activity" E:\Backups\GoalsAndActivity /E /V /C /I /F /G /H /R /K /Y /Z /D
xcopy "c:\Data\Documents\Kiwisaver" E:\Backups\Kiwisaver /E /V /C /I /F /G /H /R /K /Y /Z /D
xcopy "c:\Data\Documents\Lead letters" E:\Backups\LeadLetters /E /V /C /I /F /G /H /R /K /Y /Z /D
xcopy "c:\Data\Documents\Newsletter" E:\Backups\Newsletter /E /V /C /I /F /G /H /R /K /Y /Z /D
xcopy "c:\Data\Documents\Personal" E:\Backups\Personal /E /V /C /I /F /G /H /R /K /Y /Z /D
xcopy "c:\Data\Documents\Planet" E:\Backups\Planet /E /V /C /I /F /G /H /R /K /Y /Z /D
xcopy "c:\Data\Documents\State" E:\Backups\State /E /V /C /I /F /G /H /R /K /Y /Z /D
xcopy "c:\Data\Documents\supplier address" E:\Backups\SupplierAddress /E /V /C /I /F /G /H /R /K /Y /Z /D
xcopy "C:\Data\Documents\standard documents" E:\Backups\StandardDocuments /E /V /C /I /F /G /H /R /K /Y /Z /D
xcopy "C:\Documents and Settings\Administrator\Desktop\datagathering" E:\Backups\datagathering /E /V /C /I /F /G /H /R /K /Y /Z /D

As you can see he was backing up specific folders in My Docs, so as to miss out the likes of his My Pictures folder which he backed up independently from this script :)

I think the first time it ran it wasnt sure if the Outlook .pst file was a File or Folder, but other than that its run perfectly day in & day out :)

MushHead
10-03-2009, 10:24 PM
Always have put quotes around paths that have spaces in them.

Why would /d not be helping? That is to copy changed files.

It appears to make no difference whether spaces are put between switches or not.

Using /d means that files are copied from the source only if newer than the destination. There's a bit of a trap here in that if you copy from an NTFS partition to a FAT one, this may not work as expected because FAT drives only allow 2s filetime resolution on the directory timestamps, whereas NTFS is <= 1 second.

You may want to try /a (copy only if archive bit set, but don't reset archive bit) or /m (same, but resets archive bit on source so won't get copied unless changed).

FoxyMX
11-03-2009, 09:47 AM
Geez Chill, that's one muther of a batch file. :waughh:

Think I will make mine a bit fancier now as I didn't know you could do it like that. :banana :p


Gobe1 and MushHead: Thanks for that. Good info to know. :thumbs: