Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Say I have a folder tree such as:

C:\Users\Test\My Documents
C:\Users\Test2
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

C:\Users\Test2

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: stackoverflow.com/questions/9271107/… –  bummi Jun 4 '13 at 11:55
    
@tumchaaditya I wanted to rename My Documents to Documents. –  Guest23408290 Jun 4 '13 at 13:14
add comment

2 Answers 2

up vote 4 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
1  
@bummi Thank you! That lists exactly what I wanted. –  Guest23408290 Jun 4 '13 at 13:15
    
@JasonH: As far as I can see /D does nothing at all when coupled with /B, and thus is not even required. –  Karan Jun 5 '13 at 3:17
add comment

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(objSubfolder.name, findstr, replacestr))
            IF NewFolderName <> objSubFolder.Name THEN
                objSubFolder.Name = NewFolderName
            END IF
        enumfolders objSubfolder.path
    NEXT

END SUB

SUB Canceled
    wscript.echo "Script Canceled"
    wscript.quit
END SUB

Source: http://www.wisesoft.co.uk/scripts/vbscript_recursive_folder_rename.aspx

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

share|improve this answer
add comment

Your Answer

 
discard

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.