Delete files or folder recursively on Windows CMD

后端 未结 12 1361
悲哀的现实
悲哀的现实 2020-12-02 08:30

How do I delete files or folders recursively on Windows from the command line?

I have found this solution where path we drive on the command line and run this comman

相关标签:
12条回答
  • 2020-12-02 08:44

    Use the Windows rmdir command

    That is, rmdir /S /Q C:\Temp

    I'm also using the ones below for some years now, flawlessly.

    Check out other options with: forfiles /?

    Delete SQM/Telemetry in windows folder recursively

    forfiles /p %SYSTEMROOT%\system32\LogFiles /s /m *.* /d -1 /c "cmd /c del @file"
    

    Delete windows TMP files recursively

    forfiles /p %SYSTEMROOT%\Temp /s /m *.* /d -1 /c "cmd /c del @file"
    

    Delete user TEMP files and folders recursively

    forfiles /p %TMP% /s /m *.* /d -1 /c "cmd /c del @file"
    
    0 讨论(0)
  • 2020-12-02 08:46

    You could also do:

    del /s /p *.{your extension here}
    

    The /p will prompt you for each found file, if you're nervous about deleting something you shouldn't.

    0 讨论(0)
  • 2020-12-02 08:47

    The other answers didn't work for me, but this did:

    del /s /q *.svn
    rmdir /s /q *.svn
    

    /q disables Yes/No prompting

    /s means delete the file(s) from all subdirectories.

    0 讨论(0)
  • 2020-12-02 08:50

    For file deletion, I wrote following simple batch file which deleted all .pdf's recursively:

    del /s /q "\\ad1pfrtg001\AppDev\ResultLogs\*.pdf"
    del /s /q "\\ad1pfrtg001\Project\AppData\*.pdf"
    

    Even for the local directory we can use it as:

    del /s /q "C:\Project\*.pdf"
    

    The same can be applied for directory deletion where we just need to change del with rmdir.

    0 讨论(0)
  • 2020-12-02 08:53

    For hidden files I had to use the following:

    DEL /S /Q /A:H Thumbs.db
    
    0 讨论(0)
  • 2020-12-02 08:59

    You can use this in the bat script:

    rd /s /q "c:\folder a"
    

    Now, just change c:\folder a to your folder's location. Quotation is only needed when your folder name contains spaces.

    0 讨论(0)
提交回复
热议问题