Apostrophe at beginning of file name
Posted: 18 Feb 2021 19:31
I was helping a user on StackOverFlow who was having a problems with apostrophes in their file names. It made wonder what happens with a file name that starts with an apostrophe.
Here I used USEBACKQ but didn't use double quotes around the file name.
Then decided to take out the USEBACKQ
Obviously we know everything should work if we double quote and use USEBACKQ
Here I ran the SAME command back to back and the error message came out a bit different.
Honestly I don't know what is going on here because it is reading the file and outputs the file but still throws an error.
Here I used USEBACKQ but didn't use double quotes around the file name.
Code: Select all
C:\BatchFiles\apostrophe>for /F "usebackq delims=" %G IN ('myfile.txt) do echo %G
C:\BatchFiles\apostrophe>echo LINE'1
LINE'1
The system cannot find the file ⨛✀谀潃卭数㵣㩃睜湩潤獷獜獹整㍭尲浣硥e.
Code: Select all
C:\BatchFiles\apostrophe>for /F "delims=" %G IN ('myfile.txt) do echo %G
C:\BatchFiles\apostrophe>echo LINE'1
LINE'1
The system cannot find the file ⨑─阀.
Code: Select all
C:\BatchFiles\apostrophe>for /F "usebackq delims=" %G IN ("'myfile.txt") do echo %G
C:\BatchFiles\apostrophe>echo LINE'1
LINE'1
Code: Select all
C:\BatchFiles\apostrophe>for /F "usebackq delims=" %G IN ('myfile.txt) do echo %G
C:\BatchFiles\apostrophe>echo LINE'1
LINE'1
The system cannot find the file ⨏⌀鐀单剅剐䙏䱉㵅㩃啜敳獲杜汣晪0.
C:\BatchFiles\apostrophe>for /F "usebackq delims=" %G IN ('myfile.txt) do echo %G
C:\BatchFiles\apostrophe>echo LINE'1
LINE'1
The system cannot find the file ⨔☀耀.
C:\BatchFiles\apostrophe>echo %errorlevel%
0