The command
type “File Name with Spaces.txt”
Works!!
But
set “Fname=File Name with Spaces.txt”
type “%Fname%”
Or
type “!Fname!”
Failed !!
Message: The system cannot find the file specified
??
The command
type “File Name with Spaces.txt”
Works!!
But
set “Fname=File Name with Spaces.txt”
type “%Fname%”
Or
type “!Fname!”
Failed !!
Message: The system cannot find the file specified
??
set Fname=File Name with Spaces.txt
type "%Fname%"
should work. You don't really need the quotes in the set command in this case. But they are important when you access the variable's content in the type
command.
Edit:
I am back at a pc where I can test things again. @Squashman and @Mofi are right about the main point that you should use straight double quotes ("
) and in saying that the set "Fname=File Name & Spaces.txt"
is a legitimate and often the recommended syntax. However I would also like to mention another possible variation on the theme. When you do
set Fname="File Name & Spaces.txt"
The quotes will become part of the stored variable:
echo %Fname%
> "File Name & Spaces.txt"
and the type
command referencing a filename containing a blank and an ampersand can then be issued without the quotes:
type %Fname%
If you want to acces the contents without the surrounding quotes you can still do
echo %Fname:"=%
> File Name with Spaces.txt
(see set /?
for further details on variable handling in cmd.)