Reputation: 651
I am looking for T(current date/todays date) dated files in particular folder. C:\Users\abc\Desktop\CBS\OUTBOX.
There will T -1, T -2... files will also be there.
And there will be T dated files starting with prefix(NP and PN) and followed by date like PN27022014
and NP27022014
.
Also there is another condition, both file will be ending with 5 different extension like
PN27022014.TRN
PN27022014.BAL
PN27022014.NEG
PN27022014.NBL
PN27022014.EFG
NP27022014.TRN
NP27022014.BAL
NP27022014.NEG
NP27022014.NBL
NP27022014.EFG
I have query to check file with single prefix and ending with single extension.
@echo off
SetLocal enabledelayedexpansion
for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set year=%%c
for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set month=%%a
for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set day=%%b
set TODAY=%day%%month%%year%
echo %TODAY%
for /F "tokens=1" %%a IN ('Dir "C:\Users\abc\Desktop\CBS\OUTBOX\PN*%TODAY%*.TRN" /-C/S/A:-D
2^>nul') Do Set y=!n2! & Set n2=%%a
echo out %y%
If %y% gtr 1 ( echo 4 ) else ( echo 3 )
How to get it for both prefix with different extensions.
Query should give output 4 if there are files with each prefix and each extension greater than 1.
Upvotes: 0
Views: 62
Reputation: 41234
This will detect the number of files that match todays date filespec and tell you if 10 files are found, or not.
Date routine requires XP Pro and higher.
@echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"
set "datestamp=%DD%%MM%%YYYY%"
for /f "delims=" %%a in (' dir /b /a-d "C:\Users\abc\Desktop\CBS\OUTBOX\??%datestamp%.*" ^|find /c /v "" ') do (
if %%a EQU 10 (echo 10 files are present) else (echo incorrect number of files)
)
Upvotes: 1