Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

DOS Xcopy command help

  1. Dec 28, 2015 #1
    Hello!
    I am trying to run Dos copy command butim a confused a little about using it to copy folders to multiple folders.My problem is to write a command that will copy all folders from a source that could be something like G:\ or H:\ i.e from USB drive.Can i use G and H both at a time?
    Thanks in advance!
     
  2. jcsd
  3. Dec 28, 2015 #2
  4. Dec 28, 2015 #3
  5. Dec 28, 2015 #4

    jedishrfu

    Staff: Mentor

    An alternative approach is to zip up all the folders and files, copy the compressed zip to where you want and then unzip it in the new location.

    You might need to download the zip tool though and will need sufficient space for the zip file and the unzipped files.
     
  6. Dec 28, 2015 #5
    Thanks but what if i don't know the files or folders already?
    I'm looking for a command that will copy all the folders of a drive.....
     
  7. Dec 28, 2015 #6

    jedishrfu

    Staff: Mentor

    If you know the drive then you know the root folder.
     
  8. Dec 28, 2015 #7
    Okay!
    How about performing this operation:
    A USB drive is inserted and the drive name is G:\.I want to copy all the folders except .exe files..and want to do this silently mean without displaying the prompt window.
    Should i use @Echo off?
     
  9. Dec 28, 2015 #8

    jedishrfu

    Staff: Mentor

    I dont think you can make the operation entirely invisible. I think you'll still have a blank window popup at best.

    http://www.computerhope.com/echohlp.htm

    You can turn command echo off but you'll need to redirect command error messages and output to file or to nul.
     
  10. Dec 29, 2015 #9

    meBigGuy

    User Avatar
    Gold Member

    I'd write a perl script. Use the File:Copy package.
     
  11. Dec 29, 2015 #10
    You can also use Windows's vb script .
    Code (Javascript):

    ::file copy
    @echo off
    /min
    set command=xcopy /s /c /d /e /h /i /r /y /exclude:YourExcludedExeFiles.txt
    echo off
    %command% "%G%" "%DestinationDrive%"
    @echo off
     
    Run your wscript to createObject without arguments e.g
    CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False
    and feed its second parameter with the above script file.

    If you need this process to run automatically when the USB is inserted, I guess you would probably need to add an autoconf file also for the task.
     
  12. Dec 29, 2015 #11
    Thanks.
    I don't know much about Javascript..can you explain a bit about the commands and code you used?
     
  13. Dec 29, 2015 #12
    :: <<< is for comment
    /min <<< always minimize executed console/windows
    set command=xxx <<<< set label 'command'
    /exclude:xxx.txt <<<< exclude option for all filenames written in xxx.txt
    %command%"%G%""%DestinationDrive%" <<< execute the set command
    echo off <<< no output, keep things silent please
     
    Last edited: Dec 29, 2015
  14. Dec 29, 2015 #13

    meBigGuy

    User Avatar
    Gold Member

    Is it Visual Basic, or Javascript?
     
  15. Dec 29, 2015 #14
    It's VB script. That will also help to get things in the storage transferred :wink: ...intentionally.
     
  16. Dec 30, 2015 #15

    meBigGuy

    User Avatar
    Gold Member

    The OP saw the Javascript fomated code window and assumed it is Javascript. Just trying to point that out.

    If a perl script is desired, I can supply an example. But, I need a requirement for how the script will be invoked.
    For example, how does the program know what drive letter to copy. Let's call the command program dumpIt. Would the user type dumpIt G: in a command window?
    Or, do you need DumpIt to appear as a right mouse context for any file on the drive? Or, is dumpIt a right mouse context for the drive? Or, do we try to register a service that will run dumpIt on any USB drive placed on the computer? (not sure how to do that one)
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook