Forums before death by AOL, social media and spammers... "We can't have nice things"
|    alt.msdos.batch    |    Fun with MS-DOS batch files    |    42,547 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 41,505 of 42,547    |
|    foxidrive to Endri Azizi    |
|    Re: batch script file - copy the last bu    |
|    21 Oct 16 07:02:49    |
   
   From: foxidrive@server.invalid   
      
   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   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca