2

What's a good way to delete everything below a certain path, supplying a list of exclusions?

E.g.

C:\
    MyFolder
        MyApp
        MyConfig
        MyWorld
        MyEverything
        MyBankDetails

How to delete C:\MyFolder\*.* leaving behind MyBankDetails such that the folder structure resembles:

C:\
    MyFolder
        MyBankDetails

2 Answers 2

2

Here's a way to do it using Powershell:

get-childitem C:\Myfolder\ -exclude "MyBankDetails" -recurse | foreach ($_) {remove-item $_.fullname}

It'll recurse through C:\Myfolder and delete everything except folder MyBankDetails. You can add exclusions, both folders and files, as you wish. For example:

... -exclude "MyBankDetails","AnOtherFolder","File.txt",*.someFileExtension ...
0

Be careful about the answer above: -Exclude key works differently since 5.0 version. The above-mentioned code will remove everything except the folder MyBankDetails itself, contents will be erased.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .