Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

batch script file - copy the last business day's file of the month

38 views
Skip to first unread message

endri...@gmail.com

unread,
Oct 20, 2016, 4:04:34 AM10/20/16
to
I have to do a batch script file where I would like to copy the last business day's file of the month
for example:

business days
1=Monday
2=Tuesday
3=Wednesday
4=Thursday
5=Friday

not business days
6=Saturday
0=Sunday

(Monday 31 July 2016) is the last day of the month & is a business day copy to a backup folder



(Saturday 31 December 2016) is the last day of the month BUT is not a business day don't copy to a backup folder

than check back the first business day but the last business day of the month
(Fryday 30 December 2016) is the last business day of the month copy to a backup folder

I hope now is more clear

Thanks a lot!!!

JJ

unread,
Oct 20, 2016, 12:20:09 PM10/20/16
to
Using a batch file is way too complicated.
I'd use VBScript for this.

Zaidy036

unread,
Oct 20, 2016, 3:39:09 PM10/20/16
to
here is something to start with

SET "_DOW=%date:~0,3%"
SET i=0
For %%a in (Sun Mon Tue Wed Thu Fri Sat) DO (SET /A "i+=1" &
ECHO/%_DOW%|findstr /i /b "%%a" >nul && CALL SET NUM=%%i%%)
ECHO NUM=%NUM%
ECHO NUM=%NUM%

foxidrive

unread,
Oct 20, 2016, 7:44:40 PM10/20/16
to
Reposting this
The guy sent it to other newsgroups in multipost



On 20/10/2016 19:11, Endri Azizi wrote:
> I have to do a batch script file where I would like to copy the last business day's file of the month for example:
>
> business days
> 1=Monday
> 2=Tuesday
> 3=Wednesday
> 4=Thursday
> 5=Friday
>
> not business days
> 6=Saturday
> 0=Sunday
>
> (Monday 31 July 2016) is the last day of the month & is a business day copy to a backup folder
>
>
>
> (Saturday 31 December 2016) is the last day of the month BUT is not a business day don't copy to a backup folder
>
> than check back the first business day but the last business day of the month
> (Fryday 30 December 2016) is the last business day of the month copy to a backup folder
>
> I hope now is more clear
>
> Thanks a lot!!!
>



This is a script I wrote in crayon just now.
Actually I shredded a different script to simplify it.


If you run it on a weekend it will supply the previous Fridays date,
otherwise it will give the current date.

:: Date backward and skipping weekends
@echo off
set qty=%1
set separator=%~2
if "%~1"=="" set qty=0
echo >"%temp%\%~n0.vbs" s=DateAdd("d",%qty%,now)
echo>>"%temp%\%~n0.vbs" d=weekday(s)
echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^&_
echo>>"%temp%\%~n0.vbs" right(100+month(s),2)^&_
echo>>"%temp%\%~n0.vbs" right(100+day(s),2)^&_
echo>>"%temp%\%~n0.vbs" d
for /f %%a in ('cscript //nologo "%temp%\%~n0.vbs"') do set result=%%a
del "%temp%\%~n0.vbs"
endlocal& ( set "YY=%result:~0,4%"
set "MM=%result:~4,2%"
set "DD=%result:~6,2%"
set "daynum=%result:~-1%"
)
:: if the daynum is a weekend then run the batch file again to get the friday
set "weekend="
if %daynum% EQU 1 set /a weekend=qty - 2
if %daynum% EQU 7 set /a weekend=qty - 1
if defined weekend %0 %weekend%

set "day=%YY%%separator%%MM%%separator%%DD%"
echo variable %%day%% is set to "%day%" (without the quotes)
echo variable %%YY%% is set to %YY%
echo variable %%MM%% is set to %MM%
echo variable %%DD%% is set to %DD%
echo.
echo daynum is "%daynum%"
echo daynum=1 Sunday
echo daynum=2 Monday
echo daynum=3 Tuesday
echo daynum=4 Wednesday
echo daynum=5 Thursday
echo daynum=6 Friday
echo daynum=7 Saturday
pause & goto :EOF

pro...@berkeley.edu

unread,
Oct 29, 2016, 2:27:32 PM10/29/16
to
That's great! Very useful! Thanks for posting. I've been reluctant to
chime in on these posts dealing with scheduling questions because I'm
now retired and don't have any enterprise network access; in other
words, I'm no longer in a position to be able to test any code.

About fifteen years or so ago there was a lot of useful discussion of
such issues in the microsoft.public.win2000.cmdprompt.admin newsgroup.
I just had a quick look and dug up a useful thread: search for
'schedbydayofmonth' in that NG. I also remember Frank Westlake wrote a
nice program called ATX. Lots of good stuff regarding scheduling in that
NG.

--
Phil Robyn
0 new messages