Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Ordinary bat scripts make windows the strongest.

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 303

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report