VBA to change the name of multiple files in multiple folders to include part of the folder name

SideburnsJim

New Member
Joined
Nov 24, 2017
Messages
6
I have hundreds of folders that all have the naming convention: "Organisation_2023_03_17_01_40_24" where "Organisation_" is constant, but "2023_03_17" refers to the date the files in the folder were created and "_01_40_24" refers to the time.

Within each folder there are 4 .txt files named: Organisation_balances, Organisation_categorisation, Organisation_events, Organisation_progress

I would like a VBA script that would allow me to select which folders I want to work with, and then change the name of the four files within each folder to use the date element of the folder. Eg; Organisation_balances.txt becomes Organisation_balances_2023_03_17.txt

Can someone please advise on how to do this?

Many thanks
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Use FileDialog(msoFileDialogFolderPicker) to select a folder (full path), though it can only select one folder at a time so it would need to be in a loop to select multiple folders. Then use string functions like InStr and Mid to parse the last folder each full path to extract the date element and the Name statement to rename the .txt files.
 
Upvote 0

Forum statistics

Threads
1,215,692
Messages
6,126,228
Members
449,303
Latest member
grantrob

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top