Reputation: 883
I'm trying to write a simple loop that iterates over the lines of a datafile, containing path to specific files, and checking if they exist, this is the code i have so far:
:: read file line by line
for /f "tokens=*" %%a in (%DATAFILEPATH%) do (
IF EXISTS %%a (
echo FILE %a EXISTS
)
)
pause
And i get the following error message, but i dont understand why:
%a was unexpected at this time.
Thanks in advance.
Upvotes: 0
Views: 1008
Reputation: 38643
You had two main problems, the first being a plural EXISTS
and the second a singular %a
try it like this:
REM read file line by line
FOR /F "TOKENS=*" %%a IN (%DATAFILEPATH%) DO (
IF EXIST "%%~a" ECHO FILE %%a EXISTS
)
PAUSE
If the location identified from %DATAFILEPATH%
was a folder/directory then you'd change the IF
line to IF EXIST "%%~a\" ECHO FOLDER %%a EXISTS
Upvotes: 1