Solved Loop is deleting the Input file

November 9, 2018 at 09:59:22
Specs: Windows 7
This is my first batch script , and parts of them are working :-).

Please help to let me know where I am doing it wrong.

:: begin batch script
@echo off & setlocal
cd F:\BTR
set f=
set /p f=< List.txt
if not defined f (
echo " All files Processed" > Complete.txt
goto :eof
CALL F:\ICR\cdr.bat %f% -Wait
IF %ERRORLEVEL% NEQ 0 ( exit /b 1 )
find /v "%f%"<List.txt>temp
move /y temp List.txt
::========= end batch

I have a list.txt file from which I take the name and pass it to the below commad as %f%

CALL F:\ICR\cdr.bat %f% -Wait

so if the List.txt has 10 files, the command will take each file and put in in the place of %f% and run the call command 10 times

and after the command is executed successfully, I am trying to remove the file which is processed from List.txt and if all the files are processed, I am generating a dummy file to notify me that List.txt process is complete and the .bat is successfully executed.

The problem is the loop logic is not working as I expected, and the list.txt is getting empty.

can any one please let me know what is wrong in my script.


message edited by Chanyak23

See More: Loop is deleting the Input file

Report •

November 11, 2018 at 13:50:24
✔ Best Answer
The below does not remove anything from any file&exits on error:

@echo off&setlocal enabledelayedexpansion
pushd F:\BTR
for /f %%a in (list.txt) do (
echo processing %%a...
call F:\ICR\cdr.bat %%a
if not !errorlevel!==0 exit/b
echo Finished without error^^!

i5-6600K[delid]@4.8GHz/4.4GHz@1.424v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-14-14-28 1T 2800MHz@1.37v
MSI Armor RX 570 4GB@1400Mhz core@1.18v/1940MHz

Report •
Related Solutions

Ask Question