Forum Home
Press F1
 
Thread ID: 68762 2006-05-10 05:50:00 bat file xcopy problem Morgenmuffel (187) Press F1
Post ID Timestamp Content User
453672 2006-05-10 05:50:00 win2k os

contents of my batch file (quick and easy back-up)


xcopy d:\*.* j:\*.* /y/d/s
xcopy C:\Documents and Settings\nigel\Desktop\*.* j:\NIGEL_desktop\*.* /y/d/s
xcopy C:\Documents and Settings\nigel\My Documents\*.* j:\NIGEL_docs\*.* /y/d/s


Originally i had only the first line and it worked fine, but I have since added the next 2 lines and they don't action I am guessing it has to do with there being spaces in the paths (documents<space>and<space>settings) but I an unsure of how to get around this

cheers
Morgenmuffel (187)
453673 2006-05-10 05:53:00 win2k os

contents of my batch file (quick and easy back-up)


xcopy d:\*.* j:\*.* /y/d/s
xcopy C:\Documents and Settings\nigel\Desktop\*.* j:\NIGEL_desktop\*.* /y/d/s
xcopy C:\Documents and Settings\nigel\My Documents\*.* j:\NIGEL_docs\*.* /y/d/s


Originally i had only the first line and it worked fine, but I have since added the next 2 lines and they don't action I am guessing it has to do with there being spaces in the paths (documents<space>and<space>settings) but I an unsure of how to get around this

cheers

What if u put an " before C and after settings? Or after desktop?
Speedy Gonzales (78)
453674 2006-05-10 05:54:00 xcopy "C:\Documents and Settings"\nigel\Desktop\* . * :\NIGEL_desktop\* . * /y/d/s

Quotes (") around any parts with DOS-illegal characters like spaces (or the whole address) will fix it .

P . S . spaces aren't actually illegal, they are recognised as separators in a command line . So the command interpreter sees "C:\Documents" as a legal name, then doesn't understand "and" and "Settings" . The quotes make it into a single item .
Graham L (2)
453675 2006-05-10 06:04:00 The " also applies to files in the menu in XP . And most probably 2k .

You'll notice, if u go to a program under start / all programs / program name / properties .

The " is at the start and end of the file you want to run .

Since the programs are in the program files folder .
Speedy Gonzales (78)
453676 2006-05-10 06:14:00 It probably applies back to Win 95 . ;) It's just a byproduct of the long names not being compatible with the DOS command interpreter . The interpreter sees a line as a sequence of tokens with separator characters between .

Valid separators would be space, TAB, and probably LF and FF . . . *nix can take CR, too) .

You just need a way to insert a string containing separators as a single token . Quotes do that . They can surround just the part of a pathname containing spaces, or the whole pathname . (But don't carry this to extremes: putting the closing quotes after the destination path or, even worse, "/" options, would not be nice . ;)
Graham L (2)
453677 2006-05-10 06:31:00 Thanks all that worked

I did realise spaces were seperators (from my dos days), rather embarassed when the answer was so obvious,

thanks again
you saved me pulling out the rest of my hair
Morgenmuffel (187)
453678 2006-05-10 06:56:00 This thread has interested me because I have a batch file for backing up my data but found it didn't work for backing up all my selected directories. Will have to try it again but I'm wondering whether the batch file needs to be in the root directory (ie C: drive) or can it be anywhere? FoxyMX (5)
453679 2006-05-10 07:01:00 It's usually convenient to have it in the root directory, because the modern versions make changing the DOS "PATH" environment variable a bit difficult . I'm sure it can be done, but I haven't bothered . . . just put batch files in the root .

C:\ is always in your PATH . The black screen comes up with a C:\ prompt, so launching a batch file will always work if the file is there .

You can run any executable (or . BAT) if it's in your PATH, or if you give the full pathname .

echo %PATH should tell you your current path .
Graham L (2)
453680 2006-05-10 11:26:00 Seems like I do need to have the batch file on the C:\ drive or it won't run .

Also finally got the batch file backing up my selected directories . :thumbs:
FoxyMX (5)
453681 2006-05-11 02:32:00 You don't have to have it there; as I said, it's just convenient .

If you put a batch file in your "My Documents" directory, you would have to type (this might not be exactly right, but you will get the idea) "c:\"Documents and Settings\FoxyMX\Desktop\"My Documents\backup . bat", unless you can get that path into your PATH .

Another way would be to have one batch file (called, say, "runit . bat") in C:\ which you call . It will start the other one, which you can have in "My Documents" or anywhere else convenient to you . That could look like
@echo off
echo starting backup . bat . . .
"C:\Documents and Settings\ . . . . {etc} . . . \backup . bat"
This could become very clever . . . e . g . allow you to give the name of the actual script to be run as an argument .
Graham L (2)
1 2