Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: question - batch file only works with "unofficial" directory name


01 Jan 2013   #1

Win7 professional 64bit
 
 
question - batch file only works with "unofficial" directory name

Hello...
I'm using a command line batch file to backup files from my Windows 7 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 Windows 7 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 System SpecsSystem Spec
.

01 Jan 2013   #2
Microsoft MVP

64-bit Windows 8.1 Enterprise
 
 

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 System SpecsSystem Spec
01 Jan 2013   #3

Microsoft Community Contributor Award Recipient

Windows 8.1 Pro with Media Center
 
 

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:

Name:  Path_Quotes_1.png
Views: 7
Size:  2.0 KB

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:

Name:  Path_Quotes_2.png
Views: 10
Size:  4.4 KB

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:

Name:  Path_Quotes_3.png
Views: 10
Size:  6.1 KB

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

Kari


My System SpecsSystem Spec
.


01 Jan 2013   #4
Microsoft MVP

64-bit Windows 8.1 Enterprise
 
 

Quote   Quote: Originally Posted by Kari View Post
Sorry the rant, an old school geek just loves to speak about command line language .

Kari
My System SpecsSystem Spec
05 Jan 2013   #5

Win7 professional 64bit
 
 

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 System SpecsSystem Spec
05 Jan 2013   #6

Microsoft Community Contributor Award Recipient

Windows 8.1 Pro with Media Center
 
 

You are welcome, Robert.
My System SpecsSystem Spec
Reply

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




Thread Tools




Our Sites

Site Links

About Us

Find 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 07:53 PM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33