Getting around spaces in folder names in batch files?

Soldato
Joined
1 Sep 2005
Posts
10,001
Location
Scottish Highlands
Im trying to make a batch file to automate my backup. But ive come across a problem with folders that have spaces in them, as its seeing it as the end of the command. For example;

ROBOCOPY C:\Documents and Settings\Administrator\Favorites\ X:\Favorites\ *.* /S /PURGE >>X:\Backuplog.txt

Is producing errors in the "C:\Documents and Settings\" bit. Ive tried adding "" around the whole path, but that doesn't seem to work either. Any ideas?
 
I use -

xcopy /e /y /d /c /I /h /r "Z:\www\*.*" "C:\Documents and Settings\Administrator\My Documents\Server Backup\www\*.*"

Or,

xcopy /y /d /c /I /h /r "Z:\friction_jo_status_config.php" "C:\Documents and Settings\Administrator\My Documents\Server Backup\www"

Or similar.
 
It seems it might be Robocopy that getting confused with the "" in the middle of its options. Does Xcopy allow you to only copy things that have changed or been added in the source folders?
 
You sir, are a genious :D Works perfectly now, cheers mate.

Edit; why the NVM?

Edit Edit; Hmm, well it works in my test file, but my main batch file is still producing errors :(

Edit Edit deffinately last Edit; Fixed it, was just some stupid syntax error in the main one :)
 
Last edited:
Thanks for you help ns400r. Ive managed to get it working with the robocopy command thanks to marc2003's suggestion. After looking at Xcopy, I think I prefer Robocopy as it has far more options. The problem im having now, is hiding the command screen as it working. The line I have so far is;

ROBOCOPY "C:\Documents and Settings\Administrator\Favorites" "X:\Favorites" *.* /S /PURGE >>X:\Backuplog.txt

If I change this to

ECHO off ROBOCOPY "C:\Documents and Settings\Administrator\Favorites" "X:\Favorites" *.* /S /PURGE >>X:\Backuplog.txt

The command screen is hidden, but this also causes nothing to be written to the log file. Is there a way of hiding the working of the batch, but still have the working written to the log?
 
Back
Top Bottom