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
rcrgs

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 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 System SpecsSystem Spec
.
01 Jan 2013   #2
Brink

64-bit Windows 10 Pro
 
 

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
Kari

Microsoft Community Contributor Award Recipient

 

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 System SpecsSystem Spec
.

01 Jan 2013   #4
Brink

64-bit Windows 10 Pro
 
 

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
rcrgs

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
Kari

Microsoft Community Contributor Award Recipient

 

You are welcome, Robert.
My System SpecsSystem Spec
Reply

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




Thread Tools




Similar help and support threads
Thread Forum
Command Prompt: "close: No such file or directory"
I have several batch files that I need to run from Command Prompt. For exampleecho off echo !HM | ncat 192.168.1.6 80So visually I see:C:\ncat>home.bat echo off close: No such file or directory C:\ncat>All the batch files work as desired but always return the error code. ncat.exe is in the...
Software
Batch renaming files fails, error "the system cannot find file..."
Hi all, I'm trying to rename files with batch file "bulkrename.bat", that is generated by a short program made with Visual Foxpro 9.0. Here is the source code of Foxpro program: TV recordings renamed with XML metadata tag And here is generated "bulkrename.bat": ------------------- snip...
General Discussion
How to have "thumbs.db" file Created in a local photo directory
Hi, I'd like to have the "thumbs.db" file created in its own images' directory - like it was done in Windows XP - not, in some deep subdirectory of windows, (%userprofile%\AppData\Local\Microsoft\Windows\Explorer) where I can't tell which-is-which's... The reason I want it, is this: I...
Performance & Maintenance
General sysntax guidelines for a batch file-- "my system"
I have a precoded batch file to run in command mode. It gives commands to regedit but without my specific machine info the batch fail fails. In the sample : reg load HKLM\MY_SYSTEM and refers to this on three lines MY_SYSTEM has to refer to the Win7 being used? I tried the...
General Discussion
Batch file only works in certain directory
I made a batch file that says this: @echo off cd C:\Users\John\Desktop rename ring.gif ring.jpeg The actual batch file is saved on my I:\ drive, not my C:\ drive. My I:\ drive is an internal HDD that is able to talk with my C:\ drive. When I execute the .bat file, it does nothing...
General Discussion


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 14:08.
Twitter Facebook Google+ Seven Forums iOS App Seven Forums Android App