Solved Delete the File and Capture the Status

November 16, 2017 at 06:04:04
Specs: Windows 7
Hi,

I am new to batch scripting, trying to do the below scenario in batch scripting. I tried initially to do it in DataStage but I am not getting the expected results.

I have an input file which has the below data. I have to delete the file and capture the status if the file is deleted or not in a new file.

Input File
Identifier, FileDetails
654,\\CDRT\Tele\Apps\File
655,\\CDRT\Tele\Apps\Data.txt
656,\\CDR\Tele\Apps\File.jpeg
657,\\CDRT\Tele\Apps\Tre.tif

OutPut File
Identifier, FileStatus
654,Deleted
655, File Not Found
656, Path does not exist
657,Deleted

can any one give me a idea on how to do this.

Thank you.


See More: Delete the File and Capture the Status

Reply ↓  Report •

#1
November 16, 2017 at 07:44:37
✔ Best Answer
Here you go, just checks if the files are there or not, please test test.bat & report back to me

also dont forget to change output.txt&input.txt to you specific filenames

::---------------test.bat-----------------
@echo off
set "outputfile=output.txt"
set "inputfile=input.txt"
echo Indentifier, FileDetails>%outputfile%
echo.>>%outputfile%
for /f "tokens=1,2 delims=," %%a in (%inputfile%) do (
if exist "%%b" (
echo %%a, File exists>>%outputfile%
) else (
echo %%a, File not found>>%outputfile%
)
)
::--------------test.bat------------------

i5-6600K@4.7GHz/4.5GHz cache@1.355v | 2x4GB Crucial-DDR4-2133@ 14-14-14-29 1T 2800MHz@1.345v | ASUS Z170-K | Samsung 250GB SSD 850 EVO | MSI Radeon RX 570 ARMOR 4GB@1330cc&1895mem | Corsair CX450 450W


Reply ↓  Report •
Related Solutions


Ask Question