Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Name: pball
I have this little script which has a settings file so the batch doesn't have to be edited.
echo Drag and drop settings file onto this window then hit enter
set /p settings=for /f "tokens=*" %%a in (%settings%) do (
set %%a
)This simple lets you drag and drop the settings file in the cmd window and sets the variable to the file path. The problem is I get this error when the for loop tries to run.
Drag and drop settings file onto this window then hit enter
"F:\Encoding\Scripts\Auto Encoder\settings_pball.txt"
Environment variable F:\Encoding\Scripts\Auto not defined
settings file not foundThe setting file has var=setting for different things one per line. If works fine when I use a for loop to get the setting file that is in the same folder.
for /f "tokens=*" %%x in ('dir /b settings*.txt') do (
set settings=%%x
)That is currently used to get the settings file from the same folder as the script.
I just want to know why I get this error when I try to use the drag and drop method. I use that input method with many other scripts I've made.

Try:
for /f "usebackq tokens=*" %%a in ("%settings%") do (
set %%a
)If your file name contains a space, which is a delimiter for the "in" part of the for loop, it expects the part before the space to be one file and the next part to be another and so on.... If you simply surround it in double quotes then it is parsed as a string, but if you use the usebackq option the "meaning" of the quotes change, double quotes can then used for file names. It will still work fine for files without spaces, so I think it should solve your problem completely.

Thanks, I got it working by removing the quotes from the %settings% in the for loop. Since if you drag a file with a space in it's file path it adds quotes.
So it all works now, whether the settings file has spaces or no spaces in it's path.
Thanks, this one really bugged me since it didn't seem different from any other time I've tried doing this.
EDIT
is it just me or is thread above other threads that have newer posts?

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |