question - batch file only works with "unofficial" directory name


  1. Posts : 5
    Win7 professional 64bit
       #1

    question - batch file only works with "unofficial" directory name


    Hello...
    I'm using a command line batch file to backup files from my W7 Pro x64 machine to an external USB HD. Basically, "xcopy c:\......\my documents\*.*" "external HD". I couldn't get this to work until I truncated the source directory to "documents" instead of "my documents" [the name that the W7 installer specified]. While the batch file now runs and does what it's suppose to do, I'm mystified as to why the source directory needs to have a truncated name in the batch file rather that the one it has "officially." Any insight into this is appreciated.
    ...robert
      My Computer


  2. Posts : 71,977
    64-bit Windows 11 Pro for Workstations
       #2

    Hello Robert,

    "My Documents" is just a symbolic link to "Documents" for backwards compatibility for older programs that still reference "My Documents". "Documents" is the true folders name. It's the same with all of the "My...." user folders.

    Hope this helps, :)
    Shawn
      My Computer


  3. Posts : 17,545
    Windows 10 Pro x64 EN-GB
       #3

    In addition to what Brink told you above, in case you need to use batch files or command line also in the future: you seem to have a syntax error in your XCOPY command syntax.

    If no folders and files on path have spaces, you do not need quotation marks ("). However, if a folder or file has space(s) on its name, the whole path must be between quotation marks. Important is that quotation marks when used come at the beginning and the end of the path, not at the beginning of the command line.

    Your quotation marks, at least on your post above, are wrong. Let's say you really had a folder called My Documents on C:\Users\Your_Username\My Documents, and you would like to copy it to D: drive on folder called Docs. According to your post you would give that command as:
    Code:
    "xcopy c:\users\your_username\my documents\*.*" "D:\Docs"
    This would produce an error message as seen here:

    question - batch file only works with "unofficial" directory name-path_quotes_1.png

    But with correct usage of quotation marks the files would be copied. Here's the correct syntax, please notice the begin quotation mark just before the source path, not at the beginning of the command line, and the end quotation mark just after the source path. Destination path in this example of mine does not need quotation marks because it does not contain spaces:
    Code:
    xcopy "c:\users\your_username\my documents" D:\Docs
    Also notice that wildcards *.* are useless with XCOPY command. XCOPY always copies all files of the folder.

    With this small change the content of the folder My Documents would be copied:

    question - batch file only works with "unofficial" directory name-path_quotes_2.png

    If you also want to copy subfolders and files on them you need to add handle /s, and if you want even to copy empty subfolders you need to add handle /e to the command line:

    question - batch file only works with "unofficial" directory name-path_quotes_3.png

    Sorry the rant, an old school geek just loves to speak about command line language .

    Kari
      My Computer


  4. Posts : 71,977
    64-bit Windows 11 Pro for Workstations
       #4

    Kari said:
    Sorry the rant, an old school geek just loves to speak about command line language .

    Kari
      My Computer


  5. Posts : 5
    Win7 professional 64bit
    Thread Starter
       #5

    Brink and Kari...
    Thanks for your comments and help. Most useful. Asking folks about command prompt issues is always a good way of telling when they got into the game. I'm glad that MS keeps them available. One can do a lot of things from "C:\" in a simpler manner than by using higher level programs. Happy New Year.
    ...robert
      My Computer


  6. Posts : 17,545
    Windows 10 Pro x64 EN-GB
       #6

    You are welcome, Robert.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 14:37.
Find Us