如何在批处理文件中使用 For /F 查找文件类型

How do I use For /F in a batch file to find file types

我有一个批处理文件,它使用 For /F 循环查找具有特定(节奏备份使用 进行备份)设置的所有文件。

For /F "delims=" %%A in ( 'Dir /B/S "*,*" ^| findstr ",[0-9][0-9]*$" ' ) Do Del "%%A"

这适用于此特殊设置(这是对 ABCDE.ZYX,1 的不寻常文件名格式的特殊搜索)。

如何重新使用 findstr 来查找所有 .bak 文件作为第二个搜索字符串?

单独的问题:

这条线 ( 'Dir /B/S "*,*" ^| findstr ",[0-9][0-9]*$" ' ) 是如何运作的? 它在做什么?请解释功能和属性。

我的工作解决方案。感谢讲解所涉及功能的大佬

@ECHO off
set cadencedeleted=0
set autodeleted=0
set altiumdeleted=0

ECHO Cadence Back-up Deletion In Progress
For /F "delims=" %%A in ( 'Dir /B/S "*,*" ^| findstr ",[0-9][0-9]*$" ' ) Do (
    Del "%%A"
    set cadencedeleted=1
)

ECHO AutoCAD Back-up Deletion In Progress
For /F "delims=" %%A in ( 'Dir /B/S "*.bak" 2^>nul ' ) Do (
    Del "%%A"
    set autodeleted=1
)
ECHO Altium Back-up Deletion In Progress
ECHO Note Altium *.pcbdoc.zip, *.schdoc.zip, *.outjob.zip, *.log,
ECHO *.prjpcb.zip, *.schlib.zip, *.pcblib.zip are the only ones deleted

For /F "delims=" %%A in ( 'Dir /B/S "*.pcbdoc.zip" 2^>nul ' ) Do (
    Del "%%A"
    set altiumdeleted=1
)

For /F "delims=" %%A in ( 'Dir /B/S "*.SchDoc.zip" 2^>nul ' ) Do (
    Del "%%A"
    set altiumdeleted=1
)

For /F "delims=" %%A in ( 'Dir /B/S "*.OutJob.zip" 2^>nul ' ) Do (
    Del "%%A"
    set altiumdeleted=1
)

For /F "delims=" %%A in ( 'Dir /B/S "*.log" 2^>nul ' ) Do (
    Del "%%A"
    set altiumdeleted=1
)

For /F "delims=" %%A in ( 'Dir /B/S "*.PcbLib.zip" 2^>nul ' ) Do (
    Del "%%A"
    set altiumdeleted=1
)

For /F "delims=" %%A in ( 'Dir /B/S "*.SchLib.zip" 2^>nul ' ) Do (
    Del "%%A"
    set altiumdeleted=1
)

For /F "delims=" %%A in ( 'Dir /B/S "*.prjpcb.zip" 2^>nul ' ) Do (
    Del "%%A"
    set altiumdeleted=1
)
ECHO Deletion checks

IF %cadencedeleted%==1 (
    ECHO Cadence backup files deleted
) ELSE (
    ECHO Cadence backup files not found
)

IF %autodeleted%==1 (
    ECHO AutoCAD backup files deleted
) ELSE (
    ECHO AutoCAD backup files not found
)

IF %altiumdeleted%==1 (
    ECHO Altium Backup files deleted
) ELSE (
    ECHO Altium Backup files not found
)

ECHO on
TIMEOUT 5