To clean up a project I need to find all (sub)folders named palette-library starting from the current location of a batch script file and then delete all its contents except for a folder called penstyle-opacity textures and a file called penstyle-opacity.plt. I use Windows 7.

I Googled a lot but so far I only found snippets that can either search, find and delete all the contents of a folder or delete all except the specific file from a pre-defined location. However, I can't manage to put the two together.


Maybe not the most elegant way, but you can first archive files by mask, then erase your file tree, and then unpack archive with paths.

For example:

7z a -r my_archive penstyle-opacity.plt


7z a -r my_archive "palette-library\penstyle-opacity textures\penstyle-opacity.plt"

Try and choose what fits you better.

  • Thank you! Isolating the two files that I want to keep first is a great idea, but unfortunately that is only part of the solution. I still need the other steps to be automated as well... – FerdinandCreanimo Sep 21 '15 at 9:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.