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

Windows regularly deletes the batch script of the file before a certain day.

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Remarks:

1. For example, because there is no forfiles.exe in XP, you can use the forfiles command by copying the forfiles.exe file under windows2003 to the system32 directory of XP.

two。 This document is applicable to the windows client operating system xp win7/8/10,windows server-side operating system server 2003 to 2008 and 2012 to 2016.

3. If there are any mistakes or omissions, please point out, thank you!

Forfiles.exe and help

Description:

Select a file (or group of files) and execute a command on that file. This helps batch jobs.

Syntax:

Forfiles / p / d / c

1. See what the use of the three parameters listed is: (simple parsing)

/ 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.

two。 See what the usefulness of the three parameters listed are: (detailed parsing)

/ p: specify the location where to start the search for files, or the current directory by default if not specified.

/ m: the wildcard characters used in file lookup, such as "* .log" in the code, are all log files. Of course, you can also specify all log files that start with manmee, such as "manmee_*.log". If you do not specify this parameter, it defaults to "*. *".

/ d [{+ | -}] [{|}]: specify the last modification time of the file you want to select. "/ d-7" is used above to indicate all files based on the current day and 7 days ago.

Of course, you can also specify a specific time here, such as "/ d-08swap 18max 2009" for all files that are earlier than August 18, 2009. Note that the specified time must be in the format "MM/DD/YYYY".

/ c execute the specified command on all files in double quotes ("). The default is" cmd / c echo @ file ". What is used above is" cmd / c del / f @ path "to delete the specified file. (@ file and @ path here are variables, which will be explained below.

= example illustration =

Example 1. To copy files in the C root directory with a last modification date greater than or equal to July 1, 2007 to the D root directory:

Forfiles / p "c:\" / d "2007-7-1" / c "cmd / c copy @ path d:\"

Example 2.1 Delete files under the backup directory of disk C that were last modified 10 days ago:

Forfiles / p "c:\ backup" / d-10 / c "cmd / c echo deleting @ file... & & del / f @ path"

Example 2.2 automatically delete the test directory of disk D and the last modification date is 7 days before the file

Forfiles / p "d:\ test" / s / m *. * / d-7 / c "cmd / c del @ path"

Example 2.3 Delete the 28-day extension under the current directory to bkf file (based on the current system time)

Forfiles / m * .bkf / d-28 / c "cmd / c del @ file / f"

Syntax parsing of deleted files

Forefiles / p / m-d / c

Forfiles / p contains the full path of the file to be deleted (e.g. F:\ Logfiles) / m * .log-d-7 / c "cmd / c del / f @ path"

Explain the relevant parameters and commands

PATH: represents the full path to the file.

File: indicates the name of the file.

= case action =

1. Delete all empty directories (take deleting the d:\ test directory as an example)

Dir / ad/b/s d:\ test\ | sort / r > d:\ kill.txt

For / f "tokens=*"% I in (d:\ kill.txt) DO rd "% I"

Del d:\ kill.txt

two。 Automatically delete files and directories 7 days ago

{A shortcut to create a bat file is launched, and d:\ test is changed to the directory path you want. Date refers to the date of modification. }

Principle: first delete expired files, and then delete all empty directories, this is a complete deletion process

@ echo off

Forfiles / p "d:\ test" / s / m *. * / d-7 / c "cmd / c del @ path"

Dir / ad/b/s d:\ test\ | sort / r > d:\ kill.txt

For / f "tokens=*"% I in (d:\ kill.txt) DO rd "% I"

Del d:\ kill.txt

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: 0

*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