BAT finds all files and deletes them

Multi-level deletion

@echo off
for %%a in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
if exist %%a:\ (
::Delete the specified file in "drive letter:\"
del "%%a:\Soft.exe" /f /q 2>nul
for /d %%b in (%%a:\*) do (
::Delete the specified file in "Drive Letter:\First Level Folder"
del "%%b\Soft.exe" /f /q 2>nul
::Delete the specified file in "Drive Letter:\First Level Folder\Second Level Folder"
for /d %%c in ("%%b\*") do del "%%c\Soft.exe" /f /q 2>nul
)
)
)
pause

All delete

@echo off
for %%a in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
::Delete specified files in all subdirectories
if exist "%%a:\" del "%%a:\Soft.exe" /s /f /q 2>nul
)
pause

Reprinted at: http://www.bathome.net/thread-35465-1-1.html

Delete files before the specified date

@ echo off
forfiles /p .\ /s /m file*.* /d -3 /c "cmd /c echo @file>>.\del.txt"
forfiles /p .\ /s /m file*.* /d -3 /c "cmd /c del @path"
pause

/p specifies the directory .\ is the current directory or you can specify a specific directory such as:
forfiles /p “C:\Users\administrator\Desktop\test”

/s recurse to subdirectories

/m Search for the file name to be deleted, the default is .

/d -3 means 3 days ago

/c means to execute the command to be executed, which needs to be enclosed by "", such as "cmd /c del" means to execute the del command of cmd

@file
Return the file name.
@fname
Return the file name without extension.

@ext
Only the extension of the file is returned.

@path
Returns the full path of the file.
@relpath
Returns the relative path of the file.

@isdir
If the file type is a directory, return "TRUE";
If it is a file, "FALSE" is returned.

@fsize
Returns the file size in bytes.

@fdate
Returns the date when the file was last modified.

@ftime
Returns the time when the file was last modified.

Reprinted at: https://www.cnblogs.com/joeshang/p/10487154.html

Comments

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注