How do I consolidate many folders into one?

Associate
Joined
20 Oct 2004
Posts
1,485
Apologies if this is a stupid question but I've got about 100 folders containing files that I want to "merge" into one folder. I could cut and paste everything but that would take ages. I'm sure there must be a simpler way of doing it?

Your help is greatly appreciated!

Thanks
 
If all the sub dirs have a common root and nothing else is in there then just do a search from there and cut the files from the search results and paste into a new folder.

If there are other files/folders in the root/search path you don't want then as long as the files have something in common, like part of the file name or the extension, then search on that and c'n'p as above.

Or could knock up a batch file.
 
VBS to do this here:

Code:
Set objfso = CreateObject("Scripting.FileSystemObject")

CurrentPath = objfso.getAbsolutePathName("")
Set strFolderPath = objfso.GetFolder(CurrentPath)

'Enter folder path to move the items too
DestFolder = "C:\examplefolder\"

If objfso.folderexists(DestFolder) = false then
objfso.createfolder(DestFolder)
End If

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colSubfolders = objWMIService.ExecQuery _
    ("Associators of {Win32_Directory.Name='" & strFolderPath & "'} " _
        & "Where AssocClass = Win32_Subdirectory " _
            & "ResultRole = PartComponent")

For Each objFolder in colSubfolders

    GetSubFolders strFolderPath
Next

Sub GetSubFolders(strFolderPath)
    Set colSubfolders2 = objWMIService.ExecQuery _
        ("Associators of {Win32_Directory.Name='" & strFolderPath & "'} " _
            & "Where AssocClass = Win32_Subdirectory " _
                & "ResultRole = PartComponent")

    For Each objFolder2 in colSubfolders2
        strFolderPath = objFolder2.Name

	Set Folder = objfso.GetFolder(objFolder2.Name)
	Set Files = Folder.Files

	For each ObjFile in Files
	'wscript.echo "Filename: " & objFile
	objfso.movefile objFile, DestFolder
	Next

        GetSubFolders strFolderPath
    Next
End Sub

Just copy the code above, paste it into a text file, change the DestFolder path to be wherever you want to save the files, then save it in the folder that contains the folders you want to strip out. Then just double click it and it should move all the files to the named DestFolder path.

I suggest taking a backup of your folders first though :D
 
Back
Top Bottom