Windows Commands – Batch File Commands

Windows Commands * * * @echo, timeout [code lang=”shell”] :: comment line @echo off Start /WAIT "C:\Program Files\FreeFileSync\FreeFileSync.exe" "C:\Users\oguzhank\sync.ffs_batch" Start "C:\my.exe" date /t time /t @echo """""""""""""""""""""""""""""""""""""""""""""""""" @echo " ) ) ( ) " @echo " ( ( /( ( ( /( )\ ) ( /( ( " @echo """""""""""""""""""""""""""""""""""""""""""""""""" timeout /t 60 /nobreak exit [/code] * * * if, robocopy, move How to get yesterday’s date: [code lang=”shell”] ::author @oguzhankinik @echo Started archiving operation. @echo off set year=%date:~0,4% @echo off set month=%date:~5,2% @echo off set day=%date:~8,2% ::DateDiff.cmd [days_previous] @echo off if [%1]==[] %0 1 echo y=date-wsh.arguments(0^)> %temp%\temp-yesterday.vbs echo wsh.echo Right("0"^&Day(y^),2^)^&Right("0"^&Month(y^),2^)^&Year(y^),4^-2000 >> %temp%\temp-yesterday.vbs for /f %%d in (‘cscript //nologo %temp%\temp-yesterday.vbs %1’) do set yesterday=%%d del %temp%\temp-yesterday.vbs @echo off set yesterday set yearYesterday=%yesterday:~4,4% set monthYesterday=%yesterday:~2,2% set dayYesterday=%yesterday:~0,2% if not exist "D:\ZenFileService\Arc\" mkdir D:\Zen\Arc\ if not exist "D:\ZenFileService\Tlo\" mkdir D:\Zen\Tlo\ @echo off robocopy D:\Zen\Tlo\ D:\Zen\Arc * /move /xd /s %day%_%month%_%year% %dayYesterday%_%monthYesterday%_%yearYesterday% ::*_%month%_%year% if not exist "D:\Zen\Tlo\" mkdir D:\Zen\Tlo\ @echo Finished File Sync and Sender operations. :: print date time @echo off date /t @echo off time /t :: wait 1 minute for look up for if necessary @echo off timeout /t 60 /nobreak exit [/code] * * * start [code lang=”shell”] START D:\my.exe START /WAIT "" "D:\my.exe" [/code] * * * GOTO Loop and execute exe [code lang=”shell”] :: version: 20201109 :: author @oguzhankinik :: If bingo time stamp file was generated then this file executes the generate file operation, else recall checking part after the 15 minutes. :: print DATE TIME @ECHO off DATE /t @ECHO off TIME /t @ECHO Started file generating operation for ZEN. @ECHO Started generating JSON file operation for ZEN. @ECHO off SET year=%DATE:~0,4% ::’2020′ @ECHO off SET month=%DATE:~5,2% ::’11’ @ECHO off SET day=%DATE:~8,2% ::’09’ SET bingoTimeStampFileName=Bingo_%year%-%month%-%day%.txt ::’Bingo_2020-11-09.txt’ SET bingoFilePath="D:\SS\%bingoTimeStampFileName%" ::"D:\SS\Bingo_2020-11-09.txt" :CheckForFile IF EXIST %bingoFilePath% GOTO FoundIt @ECHO The Bingo Time Stamp File is missing with named %bingoTimeStampFileName%. It will be trying after the 15 minutes later. @ECHO Date: DATE /t @ECHO Time: TIME /t :: TIMEOUT 15 minutes @ECHO off TIMEOUT /t 900 /nobreak GOTO CheckForFile :FoundIt @ECHO Date: DATE /t @ECHO Time: TIME /t ECHO Found: %bingoFilePath% Start /WAIT "C:\Zen.exe" :: wait 1 minute for look up for if necessary @ECHO off TIMEOUT /t 60 /nobreak exit [/code] * * * EQU | equal to NEQ | not equal to LSS | less than LEQ | less than or equal to GTR | greater than GEQ | greater than or equal to Remove zero beginning of day and month [code lang=”shell”] @ECHO off SET year=%DATE:~0,4% ::’2020′ @ECHO off SET month=%DATE:~5,2% ::’11’ @ECHO off SET day=%DATE:~8,2% ::’09’ ::DateDiff.cmd [days_previous] @echo off if [%1]==[] %0 1 echo y=date-wsh.arguments(0^)> %temp%\temp-yesterday.vbs echo wsh.echo Right("0"^&Day(y^),2^)^&Right("0"^&Month(y^),2^)^&Year(y^),4^-2000 >> %temp%\temp-yesterday.vbs for /f %%d in (‘cscript //nologo %temp%\temp-yesterday.vbs %1’) do set yesterday=%%d del %temp%\temp-yesterday.vbs @echo off set yesterday set yearYesterday=%yesterday:~4,4% @ECHO %yearYesterday% :: 2020 set monthYesterday=%yesterday:~2,2% @ECHO %monthYesterday% :: 11 set dayYesterday=%yesterday:~0,2% @ECHO %dayYesterday% :: 09 if %monthYesterday% LSS 10 set monthYesterday=%monthYesterday:~1,2% @ECHO %monthYesterday% :: 11 if %dayYesterday% LSS 10 set dayYesterday=%dayYesterday:~1,2% @ECHO %dayYesterday% :: 9 @ECHO formattedYesterday=%yearYesterday%-%monthYesterday%-%dayYesterday% [/code]]]>

Leave a Reply

Your email address will not be published. Required fields are marked *