Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

Say I have a folder tree such as:

C:\Users\Test\My Documents
C:\Users\Test3\My Documents

What command can I run to search through C:\Users to check which sub folders have a My Documents folder?

So for the above it would come back with:

C:\Users\Test\My Documents
C:\Users\Test3\My Documents

But not


Also, if I wanted to script renaming any sub folders that are found to be called My Documents and rename these to just Documents, how could I achieve this?

share|improve this question
Wouldn't dir /b "My Documents" work? If not, you can parse it dir /B | findstr /R /C:"My\sDocuments"... I guess it would work, I don't have Windows installed here. To rename use ren. – Alex Jun 4 '13 at 11:32
So in this case, you want to rename "Test" to "Documents" or "My Documents" to "Documents"? – tumchaaditya Jun 4 '13 at 11:37
maybe this thread is useful for you:… – bummi Jun 4 '13 at 11:55
@tumchaaditya I wanted to rename My Documents to Documents. – Guest23408290 Jun 4 '13 at 13:14
up vote 5 down vote accepted
DIR /AD /B "My Documents" /S

for listing the folders

share|improve this answer
I'll defer to bummi, I forgot the /D switch ;) – Jason H Jun 4 '13 at 11:57
@bummi Thank you! That lists exactly what I wanted. – Guest23408290 Jun 4 '13 at 13:15
@Karan It filters the results to directories only, leaving out files. – jpmc26 Mar 16 '15 at 23:03

Here's a vbscript that will also rename the folders for you:

Root = INPUTBOX("Please enter the root folder (all subfolders will be renamed)" & vbcrlf & "e.g. C:\TEST")
IF Root="" THEN Canceled

FindStr = INPUTBOX("Please enter the string that you want to find")
IF FindStr = "" THEN Canceled

ReplaceStr = INPUTBOX("Please enter the string that you want to replace it with")
IF ReplaceStr = "" THEN Canceled

SET objFSO= CREATEOBJECT("Scripting.FileSystemObject")

EnumFolders Root

SUB EnumFolders(BYVAL Folder)
    SET objFolder = objFSO.GetFolder(Folder)
    SET colSubfolders = objFolder.Subfolders

    FOR EACH objSubfolder in colSubfolders
        NewFolderName = (REPLACE(, findstr, replacestr))
            IF NewFolderName <> objSubFolder.Name THEN
                objSubFolder.Name = NewFolderName
            END IF
        enumfolders objSubfolder.path


SUB Canceled
    wscript.echo "Script Canceled"


PS: I have not tested this. Please test with an empty directory structure first.

share|improve this answer

You must log in to answer this question.

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