Why ?
I
have a system will generate a list of files in daily bases and I need to make
sure that these file got generated by running a CMD script to check if file exist
on that folder or not , this purpose can be achieved using different way
however my monitoring was only possible to be using CMS, thus, I have wrote the
below code to achieve this goal .
How ?
Below
is a Windows CMD code that will check 19 files with pattern file{date} and date
format is differ in some files, If you run the code against these file you will
be reported if it is exist or not and you may custom the code to achieve different
goal as well ,:
1- Code below:
@echo off
for /f "tokens=2
delims==" %%G in ('wmic os get localdatetime /value') do set datetime=%%G
set year=%datetime:~0,4%
set month=%datetime:~4,2%
set day=%datetime:~6,2%
echo checking files for
today %year%/%month%/%day%%time%
::MonthName.cmd::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal
EnableDelayedExpansion
for /F "tokens=1-4
delims=.-/ " %%A in ("%DATE%") do set month=%%B
set
monstring=JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC
set /a
mm=(100%month%%%100)*3-3
:: Use a call to get %mm%
evaluated first.
call set
mmm=%%monstring:~%mm%,3%%
::echo Monthname=%mmm%
::MonthName.cmd::::::::::::::::::::::::::::::::::::::::::::::::::::::
set
elem[0]=file1_%year%%month%%day%.txt
set
elem[1]=file2_%day%%mmm%%year%
set
elem[2]=file3%day%%mmm%%year%
set
elem[3]=file4%day%%mmm%%year%
set
elem[4]=file5_%day%%mmm%%year%
set elem[5]=file6%year%%month%%day%.txt
set
elem[6]=file7%year%%month%%day%.txt
set
elem[7]=file8_%year%%month%%day%.txt
set
elem[8]=file9_%year%%month%%day%.txt
set
elem[9]=file10_%day%%mmm%%year%
set
elem[10]=file11%day%%mmm%%year%
set
elem[11]=file12%day%%mmm%%year%
set
elem[12]=%day%%mmm%%year%
set
elem[13]=file13%day%%mmm%%year%.txt
set
elem[14]=file14%day%%mmm%%year%.txt
set
elem[15]=file15_%year%%month%%day%.txt
set
elem[16]=file16_%year%%month%%day%.txt
set
elem[17]=file17_%year%%month%%day%.txt
set elem[18]=file18_%day%%mmm%%year%
cd
C:{path_to_files}\files_generation_checkup\files
::@echo on
for /L %%a in (0,1,18) do (
if exist !elem[%%a]! (call
echo FILE %%elem[%%a]%% IS EXISTS) ELSE (call echo FILE %%elem[%%a]%% DOES NOT
EXIST)
)
::if not exist !elem[%%a]!
(call echo FILE %%elem[%%a]%% DOES NOT EXIST)
::echo !elem[%%a]!