also @ TechSpot: Codemasters announces £125,000 special edition of GRID 2

Command line code to copy folders

Discussion in 'Windows OS' started by rockin1jr, Jan 28, 2012.

Post New Reply
  1. rockin1jr Newcomer, in training

    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 Newcomer, in training Posts: 21

    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 Newcomer, in training

    I just tried that, I'm still getting "Invalid number of parameters".
  4. bbearren Newcomer, in training Posts: 21

    Have you tried:

    xcopy \\computername\firstfolder\secondfolder D:\firstfolder\secondfolder /s /e
  5. rockin1jr Newcomer, in training

    Yeah I did, and Im still getting "Invalid number of parameters".
  6. jobeard TS Ambassador Posts: 12,235   +123

    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 TechSpot Enthusiast Posts: 131

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

    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 TechSpot Enthusiast Posts: 143

  10. jobeard TS Ambassador Posts: 12,235   +123

    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 Newcomer, in training

    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 TechSpot Enthusiast Posts: 131

    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\" "