Could someone please assist with the correct syntax for this? It errors out after seeing the second file in the string if it doesn't exist.
Thank you,
for /f "tokens=*" %%X in (hal.dll halacpi.dll halmacpi.dll kernel32.dll ntdll.dll ntoskrnl.exe win32k.sys winload.exe winsrv.dll) do (if exist %%X (
echo %%X
if not exist %%X (
echo %%X does not exist.
) else (
Copy %%X C:\BOOTFILES\
)
)
)
For do if exist loop
Moderator: DosItHelp
Re: For do if exist loop
You should use a simple FOR loop instead of FOR /F.
Regards
aGerman
Code: Select all
@echo off &setlocal
if not exist C:\BOOTFILES\ md C:\BOOTFILES
pushd "%SystemRoot%\system32"
for %%X in (
hal.dll
halacpi.dll
halmacpi.dll
kernel32.dll
ntdll.dll
ntoskrnl.exe
win32k.sys
winload.exe
winsrv.dll
) do (
if exist %%X (
echo %%X
copy %%X C:\BOOTFILES\
) else (
echo %%X does not exist.
)
)
popd
pause
Regards
aGerman
Re: For do if exist loop
Thank you greatly aGerman. That works!