locked
Batch command to delete files RRS feed

  • Question

  • Hello guys,

    I'am in a struggle, I'am trying to create a batch command to delete all files and folders excluding the parent and the first childs

    eg. I have a folder "Test" inside i have 4 more folders "Folder_1,Folder_2,Folder_3,Folder_4" I wan't to delete Everything inside Folder_1 to Folder_4 But save the folder itself  Test/Folder_1 to Test/Folder_4

    I use to delete everything inside a parent but I can't figure it out how to go 1 layer deeper so i don't have to run the command in every folder i want to keep

    del /q "C:\Temp\*" FOR /D %%p IN ("C:\Temp\*.*") DO rmdir "%%p" /s /q

    Friday, June 22, 2018 7:53 AM

Answers

  • Don't use batch anymore. Powershell is way more powerfull and feature rich.
    Get-ChildItem -Path C:\Temp\test\Folder_* | 
        Remove-Item -Recurse -Force
    ... and easier to read and to understand I think. ;-)

    Best regards,

    (79,108,97,102|%{[char]$_})-join''


    Friday, June 22, 2018 8:12 AM

All replies

  • Don't use batch anymore. Powershell is way more powerfull and feature rich.
    Get-ChildItem -Path C:\Temp\test\Folder_* | 
        Remove-Item -Recurse -Force
    ... and easier to read and to understand I think. ;-)

    Best regards,

    (79,108,97,102|%{[char]$_})-join''


    Friday, June 22, 2018 8:12 AM
  • The del command has the /S switch, which considers all sub folders. See the help at the command line.

    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    Friday, June 29, 2018 2:20 PM