Another Renaming Files Question

lapta301

Well-known Member
Joined
Nov 12, 2004
Messages
1,001
Office Version
  1. 365
Platform
  1. Windows
Dear All

Sorry to ask yet another renaming question but if it can be done I'm sure that one of you wizzards can.

I have a lot of audio (mp3/wma) files that I move across from an Olympus voice recorder and as the file name is worthless I would like to rename all of them to the file modified date in the format of something like yyyy-mm-dd hhss.

However there are some times where there are two files with the same date and time so something extra needs to be added to the name.

As ever any help is most gratefully received.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
You can check if a file with such a filename already exists before you rename the file and then act appropriately:

Code:
Dim strFile As String, strPth As String
Dim cnt As Long
 
strPth = "C:\SomeFolder\"
strFile = "SomeFile.mp3"
 
'check if file already exists:
If Dir(strPth & Format(FileDateTime(strPth & strFile), "yyyy-mm-dd hhss") & ".mp3")<>"" Then
    'if so then modify filename with counter:
    cnt = 1
    Do
       If Dir(strPth & Format(FileDateTime(strPth & strFile), "yyyy-mm-dd hhss") & "_" & cnt & ".mp3")<>"" Then
           cnt = cnt + 1 
        Else
            Name strPth & strFile As strPth & Format(FileDateTime(strPth & strFile), "yyyy-mm-dd hhss") & "_" & cnt & ".mp3"
             Exit Do
         End if
    Loop
Else 
    'file doesn't already exist - so name it
    Name strPth & strFile As strPth & Format(FileDateTime(strPth & strFile), "yyyy-mm-dd hhss") & ".mp3"
End if

Hopefully that will work - I've just typed it in from memory due to Excel not working on my computer at the moment :-(
 
Upvote 0
Hopefully that will work - I've just typed it in from memory due to Excel not working on my computer at the moment :-(

... gasp! Excel not working! You will be getting withdrawal symptoms. ;)
 
Upvote 0

Forum statistics

Threads
1,224,606
Messages
6,179,865
Members
452,948
Latest member
UsmanAli786

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