Batch file 如何删除以';某物';
我想删除多个子文件夹中以“an”开头的特定文件(*.jpg),但不想从其他子文件夹中删除jpeg文件 我试过命令:Batch file 如何删除以';某物';,batch-file,Batch File,我想删除多个子文件夹中以“an”开头的特定文件(*.jpg),但不想从其他子文件夹中删除jpeg文件 我试过命令: for /f "delims=" %%A in ('dir "your_path\an*" /b /ad') do echo (cd %%A & echo del /F /Q /S "*.jpg") 但此命令删除所有子文件夹中的所有jpg文件 目录不是很难: C: Users user_name My pictures
for /f "delims=" %%A in ('dir "your_path\an*" /b /ad') do echo (cd %%A & echo del /F /Q /S "*.jpg")
但此命令删除所有子文件夹中的所有jpg文件
目录不是很难:
C:
Users
user_name
My pictures
goo [Main folder]
inn_01 (sub folder)
a.jpg (to remove)
inn_02 (sub folder)
a.jpg (to remove)
...
001 (sub folder)
a.jpg (to keep)
002 (sub folder)
a.jpg (to keep)
...
从
del
命令中删除/S
:
<Prompt>del /?
Deletes one or more files.
DEL [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names
ERASE [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names
names Specifies a list of one or more files or directories.
Wildcards may be used to delete multiple files. If a
directory is specified, all files within the directory
will be deleted.
/S Delete specified files from all subdirectories.
(您可以在
“cmd/c
部分中添加IF
-子句)请直接尝试此操作。一旦准备好实际删除,请删除echo
@echo off
for /f "delims=" %%i in ('dir "your_path\inn*" /b /ad') do (
echo del /F /Q "%%~fi\*.jpg"
)
注意,请不要在del命令中添加
/S
。我也这样做了。但是如果我删除了/S,脚本不会做任何事情
@echo off
for /f "delims=" %%i in ('dir "your_path\inn*" /b /ad') do (
echo del /F /Q "%%~fi\*.jpg"
)