Ordinary bat scripts make windows the strongest.
Bat script
We often encounter the situation that a directory of the windows server needs to be deleted regularly, which can be solved by .bat script plus timing task.
Forfiles / p / d / c
/ p specifies the directory in which to look for files, and the default is the current working directory.
/ d specify a date or number of days to compare whether the last modified date of the file meets the criteria.
/ c the command executed for each file found.
Give an example
Delete the I:\ QQLive directory with the extension dll file (based on the current system time)
Forfiles / p "I:\ QQLive" / m * .dll / c "cmd / c del @ file / f"
PATH: represents the full path to the file.
File: indicates the name of the file.
Delete all files from the I:\ QQLive directory 7 days ago (based on the current system time)
Forfiles / p "I:\ QQLive" / m. / d-7 / c "cmd / c del @ file / f"
Recursively delete all files in the I:\ qycache directory
Forfiles / p "I:\ qycache" / m. / s / c "cmd / c del @ file / f"
Customize the time and path of deletion
@ echo off
Set / p dt= Please enter a date:
Set / p pth= Please enter the path:
Forfiles / p "% pth%" / m. / c "cmd / c del / a / f @ path" / d -% dt%
For / f "delims="% an in ('dir / Amurd / b / s "% pth%" ^ | sort / r') do (
Rd "a"
)
Pause
Bat detects network communication scripts (using ping)
@ echo offtitle 2_NETWORK_CHECKcolor 3echcp 65001rem ipconfigecho.... ping-n 2 10.10.17.16 >% temp%\ 1.pingfindstr "TTL"% temp%\ 1.ping > nulif% errorlevel%==0 (echo master server is normal) else (echo master server is not available) echo.pause