TechSpot

Command line code to copy folders

By rockin1jr
Jan 28, 2012
Post New Reply
  1. I have been researching xcopy and trying to find a command line tool that will correctly copy files from a networked pc to a local pc. I wish to write a script later on, but the code Ive tried keeps giving me "Invalid number of parameters".

    What Ive tried, is "xcopy /s \\computername\firstfolder\secondfolder D:\firstfolder\secondfolder"

    Oddly enough, "xcopy /s \\computername\firstfolder D:\firstfolder" works.

    This is on a computer which is my media system and I wish to have a script at bootup that will auto-transfer the files. It works for one folder deep on both sides, but not 2, as in what I have above.

    Do I need mapped drives instead? Or do I need to use robocopy?
    Thoughts anyone?
    Thanks,
    Jim
     
  2. bbearren

    bbearren TS Rookie

    Use the E switch.

    xcopy /s /e \\computername\firstfolder\secondfolder D:\firstfolder\secondfolder

    The E switch copies subfolders, even if they are empty.
     
  3. rockin1jr

    rockin1jr TS Rookie Topic Starter

    I just tried that, I'm still getting "Invalid number of parameters".
     
  4. bbearren

    bbearren TS Rookie

    Have you tried:

    xcopy \\computername\firstfolder\secondfolder D:\firstfolder\secondfolder /s /e
     
  5. rockin1jr

    rockin1jr TS Rookie Topic Starter

    Yeah I did, and Im still getting "Invalid number of parameters".
     
  6. jobeard

    jobeard TS Ambassador Posts: 8,958   +587

    the target folder is just that; a TARGET

    however, the source folder becomes a list of files IN THAT FOLDER
    so if the number of files therein is high, then your symptom is the result.

    You need a script that has the concept of Foreach
    Code:
    foreach fn in dir {
        xcopy fn targetDir/
    }
    
    Perl & PHP both provide this construct
     
  7. wrt54gs7

    wrt54gs7 TS Enthusiast

    When working with filenames with spaces put them inside quotes.
    xcopy /s "\\source1\dir 1\dir 2" "C:\temp\tmp 123"
     
  8. rockin1jr

    rockin1jr TS Rookie Topic Starter

    When I put them in quotes, it comes back saying "Invalid path 0 File(s) copied".
    What I have been working with is the following:
    "xcopy /s "\\Production\TV Shows\Mike and Molly\ D:\TV Shows\Mike and
    Molly\" "

    So what would be missing here?
     
  9. jmjsquared

    jmjsquared TS Enthusiast Posts: 144

  10. jobeard

    jobeard TS Ambassador Posts: 8,958   +587

    I've always used this
    Code:
    "xcopy /s \\Production\"TV Shows"\"Mike and Molly"\  D:\"TV Shows"\"Mike and Molly"\
    
    but this is still exposed for two issues:
    1) too many files in the source directory
    2) file names with embedded spaces
     
  11. rockin1jr

    rockin1jr TS Rookie Topic Starter

    I ended up having remove one of the folders in the path on the source computer, now it will run. I can write my script now.
    Thanks.
     
  12. wrt54gs7

    wrt54gs7 TS Enthusiast

    Enclose the source and destination with each own separate quotes. The same with my example.
    "xcopy /s "\\Production\TV Shows\Mike and Molly\" "D:\TV Shows\Mike and Molly\" "
     

Similar Topics

Add New Comment

You need to be a member to leave a comment. Join thousands of tech enthusiasts and participate.
TechSpot Account You may also...