I'm trying to use FOR loops to create a batch that checks if file exists in a directory. I'm struggling with files that has spaces with the file name and i don't want to have to use a .txt list if possible. So here is what i have tested so far.
@echo OFF
:: Variables
set Folder=D:\Test Folder
set Space=File Name With Space.txt
set NoSpace=FileNameWithoutSpace.txt
:: For Loop
FOR %%A in (%Space% %nospace%) do (
if exist "%Folder%\%%A" (
ECHO %%A exist
) else (
ECHO %%A doesn't exist
echo. )
)
Here is what it reads when turned echo back on.
(if exist "D:\Test Folder\File" (ECHO File exist ) else ( ECHO File doesn't exist echo. ) )
And if i use this code:
@echo OFF
:: Variables
set Folder=D:\Test Folder
set Space="File Name With Space.txt"
set NoSpace=FileNameWithoutSpace.txt
:: For Loop
FOR %%A in (%Space% %nospace%) do (
if exist "%Folder%\%%A" (
ECHO %%A exist
) else (
ECHO %%A doesn't exist
echo. )
)
It reads the "IF" command as:
(if exist "D:\Test Folder\"File Name With Space.txt"" (ECHO "File Name With Space.txt" exist ) else ( ECHO "File Name With Space.txt" doesn't exist echo. ) )
What am I doing wrong?