Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm absolutely positively sick of random junk folders (CyberPower, VirtualBox, etc) being dumped in to the My Documents folder in Windows. I'm using Windows 7 for clarification. No, it's not the "users file" it's My Documents, I'm also not going to call the Xbox 3 the wrong number. Now that we've clarified that I'd like to figure out a way to make a small batch program that will decimate unknown junk folders and then I'll stick it in the one place I actively allow programs to be run at startup: the startup folder in the all-users folder.

If arrays (or this in general) can not be done via a batch what would be a good platform neutral language to use to approach this problem?

share|improve this question
Vbs and powershell will have no issue what so ever scripting this. Batch you would need a lot of work arounds to do it. Couple of quick things to add, does it need to be recursive? Does the list of folders to keep need to change? – 50-3 Sep 14 '13 at 8:57
It just needs to work and preferably have an easy to maintain array for other people to adjust what folders they want to whitelist, writing something static and not easy to update wouldn't be worth it for others who want to do the same thing after we've finished and forgotten about it. And yes, by change I mean we edit the file and easily whitelist a folder. By delete I mean move to the recycling bin. VBS seems more viable than batch though I'm not very familiar with it. – John Sep 14 '13 at 10:34
You can use Vbs to open and read a txt file and build an array using the split function. Then it's just a if statement based off the output of a folder listing from the my documents location – 50-3 Sep 14 '13 at 11:03
up vote 2 down vote accepted

First, a caution. An incomplete whitelist may cause deletion of important files. Furthermore, these 'junk folders' are often required for the correct operation of software that created them. If you still opt for this solution, here's a one-liner, with line breaks for readability:

pushd C:\Users\John\Documents && 
  for /D %i in (*) do @(
    echo %i| findstr /V /I /R /C:"^Important$" /C:"^Keep me$" > NUL &&
    echo rmdir /S /Q %i
  ) & popd

In its current form, this statement does not do anything harmful. The second echo displays, rather than executes the 'rmdir' command and is included as a precaution. Check whether the script would work as intended, then remove the second occurence of 'echo'.

A brief explenation. pushd temporarily changes directory to the documents folder. for /D lists all directories in there. For each directory, findstr matches its name against the whitelist. The switches /V /I /R print only non-matching entries, make the search case-insensitive and enable regular expressions. Every directory that is to be kept is then listed as /C:"^dirname$". Directories not on the whitelist will make findstr return errorlevel zero, thus executing the command after the double ampersands, i.e. rmdir /S /Q %i, deleting that directory, empty or not, without asking for confirmation.

If run from a batch file instead of directly from the command line, replace every %i with %%i.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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