Help using the XCOPY command in DOS

Discussion in 'Software' started by lcreed, Sep 18, 2006.

  1. lcreed

    lcreed Private E-2

    I'm writing a rudimentary .bat file in DOS to copy some files. I'm using XCOPY and trying to incorporate the /exclude switch to no avail:

    xcopy U:\cad\"LES - Lake" f:\"CAD Drawings"\/e/d/k/y/exclude:".bak"
    I get an error msg back - Can't read file: ".bak"

    I've tried *.bak and not using quotations - same results.
    fyi... I'm running XP Pro on a DELL D610 ltop (1.6Ghz, 1GB RAM)

    Any help on this would be greatly appreciated. Thanks alot.
    Larry.
     
  2. matt.chugg

    matt.chugg MajorGeek

    your quotes are in the wrong places.

    You should use quotes to enclose a full filename when it contains spaces so the command reads it as the whole string as spaces are used to deliminate commands.

    eg:

    cd "documents and settings"

    The exclude command actually needs to be pointed to a file that contains a list of exclusion patterns, you would need to point to that file and to skip alkl .bak files it should just contain .bak on a single line.

    xcopy "j:\temp\*.*" "j:\new folder\" /EXCLUDE:c:\exclude.txt /E /K /C /Y

    The above command will copy all files and folders in the folder j:\temp\ to j:\newfolder\ copying subdirectories including empty ones, continuing if there is an error (ie not stopping when a file fails) copying the attributes of the files (xcopy normally removes any read only attribs) and not asking to confirm overwriting
     
  3. lcreed

    lcreed Private E-2

    Worked like a charm. Thanks alot. Never would have thought to create an exclude file.

    If I want to exclude more than just one extension, do I just put them on separate lines in the exclude.txt file? eg. Line 1 - *.bak Line 2 - *.tmp etc. etc. or if I'm excluding a directory, would it be
    C:\Documents and setting\me\local settings\ - on a single line to exclude the "local settings" directory?

    Thanks again.
     
  4. matt.chugg

    matt.chugg MajorGeek

    don't put the '*' in there, its not like that, its a match not a pattern.

    so bak on a line would match any .bak files but would also match anything with /bak/ etc in the path so just use .bak or .tmp

    And yes the rest of what you say is right, 1 match to a line and the C:\Documents and setting\me\local settings\ would exlude everything that includes that text in a full filename.
     
  5. lcreed

    lcreed Private E-2

    Thanks again for the help!
    Creed.
     
  6. matt.chugg

    matt.chugg MajorGeek

    No problem. Glad you got it sorted. :)
     
  7. jcdizon103178

    jcdizon103178 Private E-2

    Hi. James here from Philippines. is there anyone can help me with xcopy command in DOS Batch File. Actually, i can successfully copy files from one drive to another drive..

    My command is here

    xcopy c:\test d:\test /e /i /y /d


    My question now is, is there a way that i can have a log file that will give me informations that the files were copied with data and time specified?

    i have tested xcopy c:\test d:\test /e /i /y /d > log.txt but it only gives me that the files were copied and no specified date and time.

    your help is very much appreciated.

    -james
     
  8. PC-XT

    PC-XT Master Sergeant

    One way I use to put the date in a log file from a .bat file is to echo a prompt to press enter to continue, then redirect the DATE command to the log file. If this is first, I then use the append redirector >> to generate the rest of the file. If you want the date and time, you could instead append the dir listing of the freshly created log file, which would be the current date and time, with some other information included, of course. You could also include a second dir listing at the end to log the time taken to perform the copy operation (last modified).
     
  9. hujorgen

    hujorgen Private E-2

    I'm trying to use xcopy to backup a large folder ~7GB. I want to copy the files every week or so but want to only copy files that are new or changed to reduce the time for backing up.

    I've tried this but it still backs up all files;

    xcopy "C:\documents and settings\folder\*.*" /a /s Z:\
     
  10. PC-XT

    PC-XT Master Sergeant

    You could use the /m switch instead of /a. That should mark the originals as backed up, so they don't get recopied every time. This assumes the editing application(s) will mark them as edited again after any change.

    Alternatively, you could try the /d switch with no date, instead of /a. That should only copy if the date of the original file is newer than the date of the backup.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds