Skip to main content
All CollectionsTutorialsGeneral
Consolidating Files in Folders
Consolidating Files in Folders

A script that you can use to consolidate files from different folders into a single folder. Helpful for consolidating game camera folders

Sam avatar
Written by Sam
Updated over 4 years ago

This is for windows

What does it do?

  1. Set the original_folder to a parent folder with the subfolders you want to consolidate.

  2. Set the destination_folder where you want the files to go

  3. It renames the files with the subfolder name so you don't have duplicate names

  4. Then it moves the files into the destination folder

Caution

The current implementation will modify the names of files in your source folder

Here Is How You Set It Up

  1. Create a text file with note pad

  2. Copy and paste the code below into the text file

  3. Rename the extension to .vbs

Heres Is How You Use It

  1. Edit the file changing your "original_folder" and "destination_folder" files to the names of your file paths. Original_folder should be a parent folder that contains the subfolders you wish to consolidate

  2. Save

  3. Double click

  4. All the files in subfolder_1 will be renamed with the subfolder name as a prefix photo1.jpg -> subfolder_1_photo1.jpg

  5. All the files in subfolder_2 will be renamed with the subfolder name as prefixx photo1.jpg -> subfolder_2_photo1.jpg

  6. All the files will be copied into the destination

  7. The way this script is currently written it will change the names of the files in the original folder so make sure you use a copy if you need to retain the original names


'Original folder - parent folder that holds subfolders to merge
original_folder = "c:\Fieldwork_parent_folder"

'Destination Folder - where you want the photos to go
destination_folder = "C:\Fieldwork\all_photos"

'Set up your variables
Set fs = CreateObject("Scripting.FilesystemObject")
Set f = fs.GetFolder(original_folder)
Set fc = f.Subfolders
'Loop through the subfolders
For Each f1 in fc
msgbox "Starting " & f1.name

SubFolderSpec = original_folder&"\"&f1.name
'Loop through the files and name them with the subfolder name
For Each f In f1.Files
'newname = ""
newname = f1.name &"_"& f.name
'msgbox newname
f.name = newname
'msgbox f.name
next

'Copy files from one folder to the other
fs.CopyFile SubFolderSpec & "\*.*", destination_folder
Next
msgbox "Done"
Did this answer your question?