You are reading a single comment by @Greenbank and its replies. Click here to read the full conversation.
  • Struggling with search terms for this on Google.

    In W10 there is a parent(?) folder with files and subfolders some of which have more subfolders. I regularly need to delete all the files inside but keep all the folders.

    Is there an easy way to do this?

    Cheers

  • From the command-line, yes.

    MAKE SURE YOU ARE IN THE RIGHT TOP LEVEL DIRECTORY.

    Here's a bunch of files:-

    C:\Users\alex\test>dir /b /s
    C:\Users\alex\test\a
    C:\Users\alex\test\b
    C:\Users\alex\test\foo.txt
    C:\Users\alex\test\a\b
    C:\Users\alex\test\a\foo.txt
    C:\Users\alex\test\a\b\more.txt
    C:\Users\alex\test\b\foo.txt
    

    Use del /s /q *.txt to delete the text files:-

    C:\Users\alex\test>del /s /q *.txt
    Deleted file - C:\Users\alex\test\foo.txt
    Deleted file - C:\Users\alex\test\a\foo.txt
    Deleted file - C:\Users\alex\test\a\b\more.txt
    Deleted file - C:\Users\alex\test\b\foo.txt
    

    Check what's left:-

    C:\Users\alex\test>dir /b /s
    C:\Users\alex\test\a
    C:\Users\alex\test\b
    C:\Users\alex\test\a\b
    

    Directory structure intact.

    Works the same if you do del /s /q * (and leaves the directories intact).

    If, using that same structure as above, I just wanted to delete all files called more.txt wherever they were I could do:-

    C:\Users\alex\test>del /q /s more.txt
    Deleted file - C:\Users\alex\test\a\b\more.txt
    
About

Avatar for Greenbank @Greenbank started