Megsie wrote:I'm not a programmer or script writer, I don't know the rules.
If you're going to be doing any of this, it's worth learning the rules, or at least the basics. Here is a nice overview on quotes and other special characters:
http://ss64.com/nt/syntax-esc.htmlMegsie wrote:I've tried putting underscores instead of spaces ...
If a file is named "My File.txt", and you
refer to it as "My_File.txt", that will not work, because the file "My_File.txt" does not exist.
If you
rename "My File.txt" to "My_File.txt", then you can refer to it with or without quotes ("My_File.txt", My_File.txt), and it will be fine either way.
Megsie wrote:I've tried . . . adding extra quotations, but the script doesn't work...
Code: Select all
forfiles -p "U:\My Documents\1. RPC\AutoMed Archive" -m *.txt -d -1 /c "cmd /c move @file "U:\My Documents\1. RPC\AutoMed Archive\Problem Files\""
Your quoting looks okay to me. You've quoted the source and destination directory paths to handle spaces, and you've quoted the entire command string, as required by the FORFILES command.
I think the problem is with how you're referring to the file to be moved in the MOVE command.
- The @file variable returns only the name and extension of the file, e.g. "MyFile.txt".
- The @path variable returns the full path to the file, e.g., "U:\My Documents\1. RPC\AutoMed Archive\MyFile.txt".
If the batch file is not located in the same folder as the files, the MOVE command will be trying to act on local files that don't exist:
Code: Select all
move C:\path\to\batchfolder\"MyFile.txt" "U:\My Documents\1. RPC\AutoMed Archive\Problem Files\"
rem The command fails, because file C:\path\to\batchfolder\"MyFile.txt" does not exist.
Both variables return an already-quoted string, so you needn't requote them:
@path is fine,
"@path" is overkill.
Replace @file with @path, test it using the ECHO command as elias suggested, and let us know how it goes.