Windows cmd scripts
Dates
rem Date in YYYYMMDD format
set MYDATE=%date:~6,4%%date:~3,2%%date:~0,2%
Delete files except the latest N
rem ---- DELETE OLD ARCHIVES
rem The result is correct if file names contain a date and/or time.
rem set listfile=%TEMP%backup_1c_%BaseName%_del_list.txt
rem Write the list of matching files to a file,
rem sorted in reverse order.
dir %arcfilemask% /O:-N /S /B > %listfile%
rem
rem delete all files except the first "N", i.e. the newest
for /F " skip=45 " %%i IN (%listfile%) DO del %%i /S /Q
rem
rem Delete the list file
del %listfile% /Q
Delete archives except the latest N: improved version
rem delete all files except the first "N", i.e. the newest
rem delims prevents spaces in file names from being treated as delimiters
for /F "skip=30 delims=;" %%i IN ('dir %dstPath%\%FileMask% /O:-N /S /B') do del "%%i" /S /Q
Calculate the day of the week
rem Store the day of the week in the DayOfWeek variable
for /f %%i in ('wmic path win32_localtime get dayofweek /format:list ^| findstr "="') do (set %%i)
Find the process using port 80
for /f "tokens=1,2,3,4,5*" %i in ('netstat -aon ^| findstr ":80" ^| findstr /i listening') do echo %j %l & @tasklist | findstr %m