Solved DELETE batch using list.txt

migooz

New member
Local time
5:57 PM
Messages
5
Hey All, I just joined this forum to find some help on a specific topic that I've been researching for like two hours now on google. I have a list of 1000 files that I need to delete from location.

Thanks in advance
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
dell
OS
Windows 7 Ultimate x64
Hi and welcome to SF.

Here's your batch file. It assumes your List.txt is newline separated.


Code:
:: th-378655.bat [TxtFileList]
@echo off
REM Delete files/folders specified in a newline delimited txt file list. 
 
set "default_list_path=C:\Users\%USERNAME%\Desktop\ListOfFilesToDelete.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.
 
Last edited:

My Computer

Computer type
PC/Desktop
OS
Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
thanks Pyprohly

thank you very much Pyprohly, one more favor can i have a same batch file for MOVE command (cut)
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
dell
OS
Windows 7 Ultimate x64
Back
Top