Windows forfiles (delete historical files) and Windows forfiles

Source: Internet
Author: User

Windows forfiles (delete historical files) and Windows forfiles
Introduction

Forfiles is a batch DELETE command that comes with windows. It is a good option to determine the time by modifying the date attribute of the file itself and use it to delete historical files.

 

 

Syntax

Forfiles [/p Path] [/m SearchMask] [/s] [/c Command] [/d [{+ |-}] [{MM/DD/YYYY | DD}]

 

[/P Path]: Specifies the Path. Of course, you can use ". "[/m SearchMask]: search method. The default value is *. * [/s]: searches through subdirectories, including the current directory [/d [{+ |-}] [{MM/DD/YYYY | DD}]: select a file whose date is greater than or equal to (+) (or less than or equal to (-) the specified date. By default, MM/DD/YYYY is the specified date, DD is the current date minus DD Day. The default value is DD. The effective range of DD is 0-32768. For example:/d-15: Search for files 15 days ago/d 2016/12/9: Specify the file date to be searched as [/c Command]: specify the command to be executed. The format is [/c "cmd/c rd/s/q @ path"]. The/c in double quotation marks is followed by the command to be executed. Variable: @ file display file name @ fname display file name without extension @ ext display file extension @ path display file complete path @ relpath file relative path @ isdir if file type is directory, the calculated value is TRUE. Otherwise, the value is FALSE. @ fsize indicates the file size in bytes. @ fdate indicates the Last modified Date stamp in the file. @ ftime indicates the last modified time stamp in the file.
Example

1. view the files or folders whose names include "--" in the "d: \ backup \ data" directory and whose modification time is greater than 15 days.

forfiles.exe /p d:\backup\data /m *-*-* /d -15 /c "cmd /c echo @path"

2. Delete,/s/q (files in the/s folder are also deleted, and the/q force delete operation is not prompted)

forfiles.exe /p d:\backup\data /m *-*-* /d -15 /c "cmd /c rd /s/q @path"

 

Note: paths do not support shared paths such as \ url \, rd (delete folders), and del (delete files)

Summary

 

 

 

Note:

Author: pursuer. chen

Blog: http://www.cnblogs.com/chenmh

All essays on this site are original. You are welcome to repost them. However, you must indicate the source of the article and clearly give the link at the beginning of the article.

Welcome to discussion

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.