Code:
C:\>echo Hello, world! > "Tom & Jerry.doc"
C:\>ren "Tom & Jerry.doc" "A different name.*"
C:\Tom & Jerry.doc -> C:\A different name.doc
1 file renamed
C:\>
Quote any filename that contains ampersands or other special characters. Quote any filename that
might contain ampersands or other special characters.
Charles,
Here's the contents of a very simple .bat file that illustrates the problem:
Echo %@Path["C & D & E & F & G\H & I & J & K.txt"]
Echo %@FileName["C & D & E & F & G\H & I & J & K.txt"]
In the real program these paths\filenames are read from an external file with @FileRead. And note that in this example, the path\filename
is enclosed in double quotes.
Here's the (complete!) results of executing the above .bat file:
Echo C
C
D
TCC: Z:\AmpersandProblem.bat [1] Unknown command "D"
E
TCC: Z:\AmpersandProblem.bat [1] Unknown command "E"
F
TCC: Z:\AmpersandProblem.bat [1] Unknown command "F"
G\
TCC: (Sys) Z:\AmpersandProblem.bat [1] The system cannot find the
file specified.
"G\"
Echo H
H
I
TCC: Z:\AmpersandProblem.bat [2] Unknown command "I"
J
TCC: Z:\AmpersandProblem.bat [2] Unknown command "J"
K.txt
TCC: Z:\AmpersandProblem.bat [2] Unknown command "K.txt"
I will note that it was not
I who put the ampersands in the file names (by now I know better than to do that) - that is the way they "arrived" from an external website, so there's no way (other than writing a C++/Visual Basic program) that I can conveniently get rid of the ampersands.
- Dan