Image

Image

Search This Blog

Sunday, December 18, 2022

Verify if the files refered by a variable in another files exists

If the file does not exist, rename the referencing file in *.BAD

SETLOCAL ENABLEDELAYEDEXPANSION 
::use local variables
set di=c:\temp
for %%f in (%di%\*.ctl) do ( 
::look in every file that ends in .ctl
for /f "tokens=1,* delims==" %%a in ('findstr /i "object_name=" "%%f"') do (
::get the name of the second file from the variable "object_name"
if not exist "%di%\%%b"(
 
::if the second file does not exist
move /y "%%f" "%%f.BAD" >>%di%\script_report.log 
::rename the .ctl file in .bad and let a trace in a logfile

                                             )  

                                                                                                                         )
                                           )
ENDLOCAL

 

 

type aaa.ctl:

[...]

 object_name=File.txt

[...]

No comments:

Post a Comment

Blog Archive