DELETE batch using list.txt


  1. Posts : 5
    Windows 7 Ultimate x64
       #1

    DELETE batch using list.txt


    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


  2. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #2

    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 by Pyprohly; 17 Aug 2015 at 08:21. Reason: Typo
      My Computer


  3. Posts : 5
    Windows 7 Ultimate x64
    Thread Starter
       #3

    thanks Pyprohly


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


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 06:24.
Find Us