Articles

Solved Batch script to check X folder if it has every calendar day

November 9, 2012 at 02:51:52
Specs: Windows 7

Hi!

I hope you guys can help me. I am not totally new to batch scripting but I really feel overwhelmed by how do I even start with this task. Basically I have like a dozen folders, let us call them X and B and C (so no special rule in naming) within a main folder called FOLDERS. Within X and B and C and the rest there are YYYYMM folders, and within each YYYYMM folder there are YYYYMMDD folders. I need to check all of them if any day is missing. OBVIOUSLY this would take forever. I wonder how to write a script that would cycle through all X B AND C folders, check if every MONTHLY folder is present, and if yes, check if every daily folder inside the months is present. Seeing as this goes back to 1999 year even, obviously the complexity is that the calendar days that should be present will be different every year. Oldest is 19990101 and newest is always today's date (or should be). If it finds anything is missing would have to log that to a txt saying within folder X monthly folder YYYYMM the days YYYYMMDD and YYYYMMDD are missing. By default all weekends WILL be missing as those are not workdays, so hence files can also not have been made.

I would be super greatful for any pointers how do I even go about coding this I mean even logically :S Can be VB script too although I am really new to that one, but whatever is more efficient.. or any script that can run on a windows 7 and does not need compiling as I have no compilers nor the right to install any (workplace)

Thank you in advance to gurus

Deana


See More: Batch script to check X folder if it has every calendar day

Report •


✔ Best Answer
November 9, 2012 at 12:39:39

And, what about holidays?
Here's a hybrid attempt at solution. It would probably be better to run it all through vbscript, but I'm not real good with it, so I went this route.
::======= begin batchscript
@echo off>log & setlocal
for %%a in (c:\folder1 c:\folder2 c:\folder3) do dir /b /s /ad %%a>%%~na
set st=12/31/1998
:1
for /f "tokens=1-3" %%a in ('dates.vbs %st%') do (
:: some debugging left in
::echo %%a
::echo %%b
set st=%%a
set yymm=%%b
set yymmdd=%%b%%c
)
if not defined st goto :eof
for %%a in (folder1 folder2 folder3) do (
find "\%yymm%\"<%%a && (
find "\%yymmdd%"<%%a || >>log echo %%a %yymmdd%
) || (
>> log echo %%a %yymm%
)
)
:: this pause is also debugging leftover. disabled
::pause
goto :1
::========== end batchscript

'=========== begin vbscript "dates"
test=datepart("w",wscript.arguments(0),vbMonday)
if test=5 then adder=3 else adder=1
dateout=dateadd("d",adder,wscript.arguments(0))
if datediff("d",date,dateout)>0 then wscript.quit
mo="0"&datepart("m",dateout)
mo=right(mo,2)
dd="0"&datepart("d",dateout)
dd=right(dd,2)
wscript.echo dateout&" "&datepart("yyyy",dateout)&mo&" "&dd
'====== end vbscript

vbscript is tested, batch is not yet.



#1
November 9, 2012 at 06:58:04

You'd have to have a config file, with all the correct dates, which would parse the first, token and then last, as the limit.
Then it'd begin with the first folder, use findstr to determine if the date is present that is if it's stored in a text file, go through a loop increasing the date by 1. Each time that would finish it would be compared to the limit. Once the limit is reached the month number will be increased by 1, then it'll refer back to the config file, and return to that. Once month 12 is finished, it'll increase the year by 1. Not something i'm going to do, but that's the logic behind it.

Report •

#2
November 9, 2012 at 07:56:00

Hmmm thanks I will try that.

Report •

#3
November 9, 2012 at 09:38:07

So if I'm understanding the OP, the folder structure is:
FOLDERS\X\YYYYMM\YYYYMMDD
FOLDERS\B\YYYYMM\YYYYMMDD
FOLDERS\C\YYYYMM\YYYYMMDD

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
November 9, 2012 at 12:39:39
✔ Best Answer

And, what about holidays?
Here's a hybrid attempt at solution. It would probably be better to run it all through vbscript, but I'm not real good with it, so I went this route.
::======= begin batchscript
@echo off>log & setlocal
for %%a in (c:\folder1 c:\folder2 c:\folder3) do dir /b /s /ad %%a>%%~na
set st=12/31/1998
:1
for /f "tokens=1-3" %%a in ('dates.vbs %st%') do (
:: some debugging left in
::echo %%a
::echo %%b
set st=%%a
set yymm=%%b
set yymmdd=%%b%%c
)
if not defined st goto :eof
for %%a in (folder1 folder2 folder3) do (
find "\%yymm%\"<%%a && (
find "\%yymmdd%"<%%a || >>log echo %%a %yymmdd%
) || (
>> log echo %%a %yymm%
)
)
:: this pause is also debugging leftover. disabled
::pause
goto :1
::========== end batchscript

'=========== begin vbscript "dates"
test=datepart("w",wscript.arguments(0),vbMonday)
if test=5 then adder=3 else adder=1
dateout=dateadd("d",adder,wscript.arguments(0))
if datediff("d",date,dateout)>0 then wscript.quit
mo="0"&datepart("m",dateout)
mo=right(mo,2)
dd="0"&datepart("d",dateout)
dd=right(dd,2)
wscript.echo dateout&" "&datepart("yyyy",dateout)&mo&" "&dd
'====== end vbscript

vbscript is tested, batch is not yet.


Report •


Ask Question