Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to look for a friday's date in a filename when the weekday is Monday. All the rest of the days just look for the previous date, but Monday needs to look for Friday's date in the file name. I know it probably isn't hard. I am just using a a batch file. Can you help me?

The filename for today's files are: BELLCO070811A.TXT, (Friday's date), tomorrow's filename will be BELLCO071111A.TXT (Today's date). In the folder is two weeks' worth of files and I only need to copy the unprocessed ones which are the previous business day's files.

Here is the script I am using:

@echo off
REM this sets the date

for /F "tokens=2-4 delims=/ " %%f in ('date /t') do (
 set mm=%%f
 set dd=%%g
 set yy=%%h
)
set fullyear=%yy%

Rem next line grabs the last two digits of the year
set yy=%yy:~-2%




REM *****************************************************
REM * The next line is the number of days from TODAY 
REM *  you want to match.  100 - 1 would be yesterday.
REM *  100 - 2 would be two days ago, etc
REM *****************************************************
REM set /A dd=1%dd% - 100 - 0   !!!! Changed by Brien.  This line must be "-1" to grab yesterday
set /A dd=1%dd% - 100 - 1
set /A mm=1%mm% - 100 + 0

if /I %dd% GTR 0 goto DONE

set /A mm=%mm% - 1

if /I %mm% GTR 0 goto ADJUSTDAY

set /A mm=12
 set /A fullyear=%fullyear% - 1
:ADJUSTDAY

if %mm%==1 goto SET31
if %mm%==2 goto LEAPCHK
if %mm%==3 goto SET31
if %mm%==4 goto SET30
if %mm%==5 goto SET31
if %mm%==6 goto SET30
if %mm%==7 goto SET31
if %mm%==8 goto SET31
if %mm%==9 goto SET30
if %mm%==10 goto SET31
if %mm%==11 goto SET30
if %mm%==12 goto SET31

goto ERROR

:SET31

set /A dd=31 + %dd%
goto DONE

:SET30

set /A dd=30 + %dd%

goto DONE

:LEAPCHK

set /A tt=%fullyear% %% 4

if not %tt%==0 goto SET28

set /A tt=%fullyear% %% 100

if not %tt%==0 goto SET29

set /A tt=%fullyear% %% 400

if %tt%==0 goto SET29

:SET28

set /A dd=28 + %dd%

goto DONE

:SET29

set /A dd=29 + %dd%

:DONE

if /i %dd% LSS 10 set dd=0%dd%
if /I %mm% LSS 10 set mm=0%mm%

set _Cutoff2=%mm%%dd%%yy%
share|improve this question
    
Omg is that what a batch file looks like it looks like assembly thank god for Linux and python, okay it looks nicer now its been put in code Markup – squarebear Jul 11 '11 at 22:01

It's easier to count how many days have occurred in 'UNIX time' and then change that number, as I have shown in this answer - How to get date value in commandline

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .