0

我需要从已经具有扩展名类型的列表中删除多个具有相同名称但扩展名不同的文件。

我有一个批处理程序来查找文件中的字符串并制作结果文本

    @echo off
findstr /m "1090 FF" *.info > results.txt
if %errorlevel%==0 (
echo Found! logged files into results.txt
) else (
echo No matches found
)

这将创建一个扩展名为 .info 的文件列表。然后我需要获取该列表并使用文件列表删除所有文件,但我需要使用它删除所有兄弟文件。

example:
12345.info (in my list to del)
12345.cpr (need to del)
12345.emf (need to del)
12345.obj (need to del)
12345.timb (need to del)

我尝试使用它,但它只删除了 .info 文件扩展名:

@echo off
REM Delete files/folders specified in a newline delimited txt file list. 

set "default_list_path=C:\Users\%USERNAME%\Desktop\SAD_FF bat\results.txt"

if not "%~2"=="" echo Error: unexpected arguments& exit /b
if not "%~1"=="" ( set "list=%1" ) else (
    set "list=%DEFAULT_LIST_PATH%"
)

if not exist "%LIST:"=%" echo Error: list could not be found& exit /b

set /a delete_counter=0
for /f "delims=" %%I in ('type "%LIST:"=%"') do (
    if exist "%%~fI" (
        set /a delete_counter+=1
        if exist "%%~fI"\* (
            rd /s /q "%%~fI"
        ) else (
            del /q "%%~fI.*"
        )
    ) else (
        echo No such path "%%~I".
    )
)

echo.& echo %DELETE_COUNTER% files or folders were deleted.

我可以增加后面的代码来删除所有的兄弟文件吗?欢迎所有建议!

4

1 回答 1

1

尝试改变

        del /q "%%~fI.*"

        echo del /q "%%~dpnI.*"

所需的 DEL 命令仅ECHO用于测试目的。验证命令正确后,更改ECHO DELDEL实际删除文件。

于 2016-10-10T14:17:45.883 回答