+ Reply to Thread
Results 1 to 27 of 27

Renaming WAV Files in a Folder

Hybrid View

  1. #1
    Forum Contributor spiwere's Avatar
    Join Date
    01-11-2013
    Location
    IN
    MS-Off Ver
    Excel 2007
    Posts
    410

    Renaming WAV Files in a Folder

    Greetings Everyone!

    I request you for some assistance on a task that has been consuming a lot of time on a day-to-day basis. I’m currently doing this manually, which requires me to work through 1000+ files daily.

    The task entails the following:

    1. I have 1000+ wav files in a folder
    2. The naming convention is as follows: “10059853 2014-06-05 09_12_54 0123456789 -_ 12146135740 ID_16207461.wav”
    3. Each name has a unique ID at the beginning “10059853“ in this case
    4. I have another list (2000-5000) entries with some more information. One of the columns in this has unique ID, which exactly match the unique ID of the file name

    My request:

    1. I’m seeking some help to be able to create a sub-folder within the folder / outside that has 1000+ WAV files
    2. Rename the files (1000+) by picking the information from the larger list (2000-5000) for the IDs that match the IDs in the names of the “WAV files
    3. Have attached a spreadsheet with some examples and the requested output

    Appreciate all your help on this!

    Happy to answer any questions or provide further clarity (if need be).

    Best regards,
    Spi
    Attached Files Attached Files
    In your greatness, remain humble!

  2. #2
    Forum Contributor spiwere's Avatar
    Join Date
    01-11-2013
    Location
    IN
    MS-Off Ver
    Excel 2007
    Posts
    410

    Re: Renaming WAV Files in a Folder

    Good day!

    May I please request your kind assistance on this.....

    Thanks in advance!

    Best,
    Spi

  3. #3
    Forum Contributor spiwere's Avatar
    Join Date
    01-11-2013
    Location
    IN
    MS-Off Ver
    Excel 2007
    Posts
    410

    Re: Renaming WAV Files in a Folder

    Request some kind consideration on this.

    Please assist!

    Regards,
    Spi

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Renaming WAV Files in a Folder

    Hello spiwere,

    The attached workbook has the macro below added to it along with a button on the worksheet to run it. You did not say what the parent folder was. The default parent folder location is "My Documents". The user can select a different folder when the macro is run.

    Option Explicit
    
    Sub CopyAndRenameFiles()
    
      ' Thread:  http://www.excelforum.com/excel-programming-vba-macros/1016265-renaming-wav-files-in-a-folder.html
      
        Dim colFiles     As Collection
        Dim EndRow       As Long
        Dim fc           As Long
        Dim Files        As Object
        Dim FileType     As String
        Dim Item         As Variant
        Dim NewName      As String
        Dim oFolder      As Object
        Dim oShell       As Object
        Dim ParentFolder As Variant
        Dim r            As Long
        Dim Rng          As Range
        Dim SubFolder    As Variant
        Dim Title        As String
        Dim Wks          As Worksheet
        
        Const ssfPersonal As Long = 5
        
            FileType = ".wav"
            
            ParentFolder = ssfPersonal  ' Constant points to My Documents. This can also be a string like "C:\Users\Owner"
            
            SubFolder = "New Folder"
            
            Set Wks = ActiveSheet
            
            Set Rng = Wks.Range("A2:F2")
            
              ' Find the last row with data.
                EndRow = Wks.Cells.Find("*", , xlFormulas, xlWhole, xlByRows, xlPrevious, False, False, False).Row
                If EndRow < Rng.Row Then Exit Sub
            
                Set Rng = Rng.Resize(RowSize:=EndRow - Rng.Row + 1)
                
                    Set oShell = CreateObject("Shell.Application")
                    
                    On Error Resume Next
                        ParentFolder = oShell.Namespace(ParentFolder).Self.Path
                        If Err <> 0 Then
                            MsgBox "The folder '" & ParentFolder & " was Not Found.", vbCritical
                            Exit Sub
                        End If
                    On Error Resume Next
                    
                  ' Let the User choose a different folder if needed.
                    Title = "The Defauilt Parent Directory is ...   " & ParentFolder & vbCrLf
                    Title = Title & "You may choose a different folder if needed." & vbCrLf & "Click Cancel to use the Default Folder."
                    Set oFolder = oShell.BrowseForFolder(0, Title, &H271)
                    
                    If Not oFolder Is Nothing Then ParentFolder = oFolder.Self.Path
                            
                  ' Add characters if needed for proper syntax.
                    ParentFolder = IIf(Right(ParentFolder, 1) <> "\", ParentFolder & "\", ParentFolder)
                    SubFolder = ParentFolder & IIf(Right(SubFolder, 1) <> "\", SubFolder & "\", SubFolder)
                    FileType = IIf(Left(FileType, 1) <> ".", "." & FileType, FileType)
                    
                  ' Create the Subfolder if it does not exist.
                    If oShell.Namespace(SubFolder) Is Nothing Then MkDir SubFolder
            
                  ' Create a List only the files of the given file type.
                    Set Files = oFolder.Items
                    
                    Files.Filter 64, "*" & FileType
                    
                  ' Create a collection of the these files for validation.
                    Set colFiles = New Collection
                    
                        For Each Item In Files
                            colFiles.Add True, Item.Name
                        Next Item
                        
                      ' Only copy and rename files on the worksheet if found in the Collection.
                        For Each Item In Rng.Columns(1).Cells
                            r = r + 1
                            On Error Resume Next
                                If colFiles(Item.Value) Then
                                    If Err = 0 Then
                                        NewName = Format(Rng.Cells(r, "C"), "md")
                                        NewName = NewName & Format(Rng.Cells(r, "D"), "hhMMss")
                                        NewName = NewName & "_" & Rng.Cells(r, "E")
                                        Name ParentFolder & Item.Value As SubFolder & NewName & FileType
                                        fc = fc + 1
                                    End If
                                End If
                            On Error GoTo 0
                        Next Item
                    
                    MsgBox fc & " Files were Renamed and Copied to " & vbCrLf & SubFolder & ".", vbInformation
                    
    End Sub
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Forum Contributor spiwere's Avatar
    Join Date
    01-11-2013
    Location
    IN
    MS-Off Ver
    Excel 2007
    Posts
    410

    Re: Renaming WAV Files in a Folder

    Quote Originally Posted by Leith Ross View Post
    Hello spiwere,

    The attached workbook has the macro below added to it along with a button on the worksheet to run it. You did not say what the parent folder was. The default parent folder location is "My Documents". The user can select a different folder when the macro is run.

    [End Sub
    [/code]
    Thanks once again for offering to help me out. But I'm somehow unable to execute the code. This is what I have changed:

     ParentFolder = ssfPersonal  ' Constant points to My Documents. This can also be a string like "C:\Users\Owner" - to
    
    ParentFolder = "C:\Users\ABC\Desktop\Renaming\Spi"
    On running the code in it shows a message that files were copied and renamed in a sub-folder, but no files are found in the new folder that was created....

    Also, my apologies in case I wasn't clear in my request. My spreadsheet only has Columns B, C, D and E.

    The original file names in Column A and requested file name in column F are not a part of the spreadsheet. These were purely given to help understand my request. I would like the macro to read the Unique ID from Column B of the spreadsheet select the file from the Parent folder which has the same ID, and then create a copy with the new naming convention.

    Hope this clarifies my problem. Once again apologies if I wasn't clear in the first instance.

    Please advise.

  6. #6
    Forum Contributor spiwere's Avatar
    Join Date
    01-11-2013
    Location
    IN
    MS-Off Ver
    Excel 2007
    Posts
    410

    Re: Renaming WAV Files in a Folder

    Thanks a zillion times.

    I'll try this out, and shortly come back to seek any further advice or close this thread.

    You guys are awesome. Can't wait to get to work and see the magic happening.


    Thank you, Thank you!
    Last edited by spiwere; 06-08-2014 at 11:55 PM.

  7. #7
    Forum Contributor spiwere's Avatar
    Join Date
    01-11-2013
    Location
    IN
    MS-Off Ver
    Excel 2007
    Posts
    410

    Re: Renaming WAV Files in a Folder

    Thanks a zillion times.

    I'll try this out, and shortly come back ti seek any further advice or close this thread.

    You guys are awesome. Can't wait to get to work and see the magic happening.


    Thank you, Thank you!

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Renaming WAV Files in a Folder

    Hello spiwere,

    I have made a few changes to the code . This should work for now. Here is the updated code and workbook.

    Macro Version 2
    Option Explicit
    
    Sub CopyAndRenameFiles()
    
      ' Thread:  http://www.excelforum.com/excel-programming-vba-macros/1016265-renaming-wav-files-in-a-folder.html
      
        Dim colFiles     As Collection
        Dim EndRow       As Long
        Dim fc           As Long
        Dim Files        As Object
        Dim FileType     As String
        Dim Item         As Variant
        Dim NewName      As String
        Dim oFolder      As Object
        Dim oShell       As Object
        Dim ParentFolder As Variant
        Dim r            As Long
        Dim Rng          As Range
        Dim SubFolder    As Variant
        Dim Title        As String
        Dim Wks          As Worksheet
        
        Const ssfPersonal   As Long = 5     ' Points to My Documents folder.
        
            FileType = ".wav"
            
          ' This can be a Shell special folder constant or a folder path.
            ParentFolder = "C:\Users\ABC\Desktop\Renaming\Spi"
            
            SubFolder = "New Folder"
            
            Set Wks = ActiveSheet
            
            Set Rng = Wks.Range("B2:E2")
            
              ' Find the last row with data.
                EndRow = Wks.Cells.Find("*", , xlFormulas, xlWhole, xlByRows, xlPrevious, False, False, False).Row
                If EndRow < Rng.Row Then Exit Sub
            
                Set Rng = Rng.Resize(RowSize:=EndRow - Rng.Row + 1)
                
                    Set oShell = CreateObject("Shell.Application")
                    
                    On Error Resume Next
                        ParentFolder = oShell.Namespace(ParentFolder).Self.Path
                        If Err <> 0 Then
                            MsgBox "The folder '" & ParentFolder & " was Not Found.", vbCritical
                            Exit Sub
                        End If
                    On Error Resume Next
                    
                  ' Let the User choose a different folder if needed.
                    Title = "The Defauilt Parent Directory is ...   " & ParentFolder & vbCrLf
                    Title = Title & "You may choose a different folder if needed." & vbCrLf & "Click Cancel to use the Default Folder."
                    Set oFolder = oShell.BrowseForFolder(0, Title, &H271)
                    
                    If Not oFolder Is Nothing Then ParentFolder = oFolder.Self.Path
                            
                  ' Add characters if needed for proper syntax.
                    ParentFolder = IIf(Right(ParentFolder, 1) <> "\", ParentFolder & "\", ParentFolder)
                    SubFolder = ParentFolder & IIf(Right(SubFolder, 1) <> "\", SubFolder & "\", SubFolder)
                    FileType = IIf(Left(FileType, 1) <> ".", "." & FileType, FileType)
                    
                  ' Create the Subfolder if it does not exist.
                    If oShell.Namespace(SubFolder) Is Nothing Then MkDir SubFolder
            
                  ' Create a List only the files of the given file type.
                    Set Files = oFolder.Items
                    
                    Files.Filter 64, "*" & FileType
                    
                  ' Create a collection of unique Ids for the these files.
                    Set colFiles = New Collection
                    
                        For Each Item In Files
                          ' Unique Id is before first space in the file name.
                            colFiles.Add True, Left(Item.Name, InStr(1, Item.Name, " ") - 1)
                        Next Item
                        
                      ' Only copy and rename files on the worksheet if the file's unique Id is in the Collection.
                        For Each Item In Rng.Columns(1).Cells
                            r = r + 1
                            On Error Resume Next
                                If colFiles(Item.Value) Then
                                    If Err = 0 Then
                                        NewName = Format(Rng.Cells(r, "C"), "md")
                                        NewName = NewName & Format(Rng.Cells(r, "D"), "hhMMss")
                                        NewName = NewName & "_" & Rng.Cells(r, "E")
                                        Name ParentFolder & Item.Value As SubFolder & NewName & FileType
                                        fc = fc + 1
                                    End If
                                End If
                            On Error GoTo 0
                        Next Item
                    
                    MsgBox fc & " Files were Renamed and Copied to " & vbCrLf & SubFolder & ".", vbInformation
                    
    End Sub
    Attached Files Attached Files

  9. #9
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Renaming WAV Files in a Folder

    Hi Spi,

    In your data file you have two lines for Unique Id 732913.

    Is there a rule for matching the items or is it just first come, first served?

    The first item has time 08_00_54 vs 08:45:54 (.wav file prior to Spreadsheet time).
    The first item has time 09_21_54 vs 09:13:13 (.wav file after to Spreadsheet time).

    Lewis

  10. #10
    Forum Contributor spiwere's Avatar
    Join Date
    01-11-2013
    Location
    IN
    MS-Off Ver
    Excel 2007
    Posts
    410

    Re: Renaming WAV Files in a Folder

    Quote Originally Posted by LJMetzger View Post

    In your data file you have two lines for Unique Id 732913.

    Lewis
    Spot on. Yes, there is a rule. I just realized it. On downloading the WAV files from the server I noticed 2 things that will need to be incorporated in the code. They are:

    1). In most cases my server is downloading 2 copies of the same file with exactly the same name up to this point 732913 2014-06-05 08_45_54 2345654321 -_ 14155952184 i.e. excluding the ID_16184365.wav last bit of the original file name (732913 2014-06-05 08_45_54 2345654321 -_ 14155952184 ID_16184365.wav) - In these cases, I'll only like to copy and rename one of the files.

    2). Wherever there are more iterations of the same unique ID (as in the case you pointed out). I would like the code to rename and copy the unique file for that as well. To cite an example:

    Unique ID:

    • 732913 2014-06-05 08_45_54 2345654321 -_ 14155952184 ID_16184365.wav – Time is 08:45:54
    • 732913 2014-06-05 08_45_54 2345654321 -_ 14155952184 ID_16184367.wav – Time is 08:45:54
    • 732913 2014-06-05 09_21_54 2345654321 -_ 14155952184 ID_16184368.wav – Time is 09:13:13
    • 732913 2014-06-05 09_21_54 2345654321 -_ 14155952184 ID_16184375.wav – Time is 09:13:13

    I would like 2 files to be copied and renamed as follows:

    • 65084554_Rich Craft
    • 65091313_Rich Craft

    Please let me know if I don’t make any sense!
    Last edited by spiwere; 06-10-2014 at 04:32 AM.

  11. #11
    Forum Contributor spiwere's Avatar
    Join Date
    01-11-2013
    Location
    IN
    MS-Off Ver
    Excel 2007
    Posts
    410

    Re: Renaming WAV Files in a Folder

    [CODE]

    I have made a few changes to the code . This should work for now. Here is the updated code and workbook.

    [\CODE]

    I'm still getting the same error. It says that the file were Renamed and Copied, but nothing gets copied or renamed. I do get a New Folder created though. Please advise if I'm missing anything.

    Really appreciate your efforts and help!

    Regards,
    Spi

  12. #12
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Renaming WAV Files in a Folder

    Hello spiwere,

    Are you receiving an error message? If so, what is the number or error description?

    Are the files all on the same drive? If not then there will be problems with the rename statement.

  13. #13
    Forum Contributor spiwere's Avatar
    Join Date
    01-11-2013
    Location
    IN
    MS-Off Ver
    Excel 2007
    Posts
    410

    Re: Renaming WAV Files in a Folder

    Quote Originally Posted by Leith Ross View Post
    Hello spiwere,

    Are you receiving an error message? If so, what is the number or error description?

    Are the files all on the same drive? If not then there will be problems with the rename statement.
    Sorry, I was on the phone, and somehow missed these questions. Here are the answers:

    Are you receiving an error message? If so, what is the number or error description? - No error number. It just says "0" files were copied and saved whenever I run it.
    Are the files all on the same drive? If not then there will be problems with the rename statement. - Yes, they are all in the same drive

    Thanks,
    Spi

  14. #14
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Renaming WAV Files in a Folder

    Hi Spi,

    Try the attached file. I included several dummy data files in a .zip file that can be used for testing. Even though some of the dummy files have .wav extensions THEY ARE NOT .wav files. Put the dummy files in some new folder far away from real data and test the program, before you attempt to use the program on real data.

    I tested extensively using Excel 2003. It should work in your version of Excel. Since this renames and moves files, I suggest you backup your data before attempting to use the file on real data.

    There are command buttons and options on Sheet 'Main' to select:
    a. The .wav file FOLDER that contains all the .wav files
    b. The file that contains your spreadsheet data (which also could be the attached file). The file DOES NOT have to reside in the same folder that contains the .wav files.
    c. An Optional 'Start Name String' for use when selecting the 'file that contains your spreadsheet data'.


    The following features (side effects) are known to exist (which can be changed if requested):
    a. If the 'destination file' already exists in the 'destination subfolder', the file will NOT move (or overwrite) the existing file.
    b. If multiple Identical 'Unique Ids' exist, the earliest .wav file will be matched with the earliest item with the same 'Unique Id' in the worksheet.
    c. The worksheet is sorted by 'Unique Id', Date and Time by the macro. Column 'G' was added to the file (by the macro) to return worksheet to it's original sort order. The Column 'G' row numbers, are not removed by the macro.
    d. The file that contains your spreadsheet data REMAINS OPEN when processing is completed.

    Lewis

  15. #15
    Forum Contributor spiwere's Avatar
    Join Date
    01-11-2013
    Location
    IN
    MS-Off Ver
    Excel 2007
    Posts
    410

    Re: Renaming WAV Files in a Folder

    Quote Originally Posted by LJMetzger View Post

    Try the attached file. I included several dummy data files in a .zip file that can be used for testing.

    Lewis
    Dear Lewis,

    This looks amazing, but unfortunately due to my little VB knowledge I'm unable to process it.

    Could you please assist me with the steps that I need to follow. Here's what I've done:

    Selected the New 'Wav File' Folder Name - This is the folder path where my .WAV files reside

    1). What do I need to do here on this line - Default Wav Control File Start String (e.g. ABC)?
    2). Wav Control File Folder on clicking this it shows me ExcelForumR*.xls* - I'm not sure what is to be done next?

    My apologies this is a fantastic code, but I'm missing a trick or two to use it. Please accept my apologies.

    Look forward to your assistance!

    Thank you!

  16. #16
    Forum Contributor spiwere's Avatar
    Join Date
    01-11-2013
    Location
    IN
    MS-Off Ver
    Excel 2007
    Posts
    410

    Re: Renaming WAV Files in a Folder

    You both rock! I am away from office today. I'll test the code late in the evening when I get to work.

    Please accept my sincere thank you for helping me out (both of you).

    Can't wait to test it.

    Thanks a zillion times. I'll update you on the outcome or seek further advice shortly.

    Have a great day. God bless!

    Relying from phone, please forgive any typos.

  17. #17
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Renaming WAV Files in a Folder

    Hi Spi. Sorry for the confusion.

    Could you please assist me with the steps that I need to follow. Here's what I've done:
    Selected the New 'Wav File' Folder Name - This is the folder path where my .WAV files reside
    Correct.


    1). What do I need to do here on this line - Default Wav Control File Start String (e.g. ABC)?
    This is optional. It contains the starting characters of the file that contains your spreadsheet data. It is there to help you find the Excel File that contains your data. If you leave this blank, it out it will show you all Excel files in the folder that is being looked at. For example if you put ABC as the start characters, when you use the NEXT STEP, only files starting with ABC will be displayed.

    2). Wav Control File Folder on clicking this it shows me ExcelForumR*.xls* - I'm not sure what is to be done next?
    You have to select the Excel file that contains your spreadsheet data. In the case you mentioned it thinks you want all files that start with ExcelForumR and are excel files (.xls, .xlsx, .xlsm, etc). You can CLEAR the contents of the 'File Name:' box to see all files.

    It can be any excel file including my file which contains your original data.

    After you select the file name the folder will be displayed on line 9 and the file name will be displayed on line 10.

    -------------------

    Additional information:

    Sheet Name containing 'Wav Files': If your data is in 'Sheet1' you can leave this blank. Otherwise put in the name of the Sheet that contains your data.


    After you have selected everything, then click the orange command button to run the program. There should progress messages on the spreadsheet (and in the status bar at the bottom of the spreadsheet) to let you know what happened, including success or failure.

    I hope this helps.

    If I left anything out, or if you have any more problems or questions, please ask.

    Lewis

  18. #18
    Forum Contributor spiwere's Avatar
    Join Date
    01-11-2013
    Location
    IN
    MS-Off Ver
    Excel 2007
    Posts
    410

    Re: Renaming WAV Files in a Folder

    Thanks for this detailed explanation Lewis!

    Let me run this. I'll comeback to you in a bit.

    You are amazingly helpful. A genius by all means

  19. #19
    Forum Contributor spiwere's Avatar
    Join Date
    01-11-2013
    Location
    IN
    MS-Off Ver
    Excel 2007
    Posts
    410

    Re: Renaming WAV Files in a Folder


    I hope this helps.

    If I left anything out, or if you have any more problems or questions, please ask.

    Lewis
    This is fantastic Lewis. Your instructions were absolutely clear, and I was able to run the script easily today

    I've been testing this throughout the day, and will continue doing so over the next 2-days. Your script is awesome. Its just my WAV files that are coming out of the server in different ways. I'm trying to find out all possible scenarios that I might encounter.

    From today's testing, I have few observations. If these could be appended it would help a lot in testing and in real scenario too:

    1. All renamed .WAV files should go into a single folder - Currently, a separate sub-folder is getting created for each
    2. As there are multiple files with exactly the same name to this point: 732913 2014-06-05 08_45_54 2345654321 -_ 14155952184 (excluding the ID_16184365.wav). Would it be possible to move the files that have exactly the same name to this point (732913 2014-06-05 08_45_54 2345654321 -_ 14155952184) before running the final command to a new folder, and keep only 1 “Unique” WAV file for processing the naming?
    3. I would like the original files to stay as they are in the Wav File Folder - Currently, they tend to get deleted after I run the script


    Thanks for all the help!

    Thanks and regards,
    Spi

  20. #20
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Renaming WAV Files in a Folder

    Hi Spi,

    I'm glad you seemed to have success using my file.

    I won't start making any changes until you respond to my questions, so I more clearly understand what you want. All your requests can be done, it's just a question of me understanding what your requirements are.

    All renamed .WAV files should go into a single folder - Currently, a separate sub-folder is getting created for each
    I misunderstood your original question. I thought you wanted a separate Sub-Folder for each (with the name of the 'Unique Id'). What should the name of the SubFolder be? It could be today's date e.g. 20140612 or anything else you want. I could also have a cell in the spreadsheet that contains the sub-folder name (however, if you forget to change the name, there would be a lot of files in the wrong sub-folder).



    As there are multiple files with exactly the same name to this point: 732913 2014-06-05 08_45_54 2345654321 -_ 14155952184 (excluding the ID_16184365.wav). Would it be possible to move the files that have exactly the same name to this point (732913 2014-06-05 08_45_54 2345654321 -_ 14155952184) before running the final command to a new folder, and keep only 1 “Unique” WAV file for processing the naming?
    I don't understand this point. Perhaps if you show by example what you want, I would understand better.

    If you showed me something like the following I would understand.

    Original Folder: ABC
    File: www (do not delete)
    File: www 1 (delete - duplicate)
    File: xxx (do not delete)
    File: yyy (do not delete)
    File: zzz

    New Folder: ABC\DEF
    Copy of File: www (with name as wwwaa)
    File: www 1 (not copied)
    Copy of File: xxx (with name as xxxaa)
    Copy of File: yyy (with name as yyyaa)
    Copy of File: zzz (with name as zzzaa)


    I would like the original files to stay as they are in the Wav File Folder - Currently, they tend to get deleted after I run the script
    Your original request said to rename the files and put them in a subfolder. To me, that means 'Move' the file to the subfolder with the file having a different name in the subfolder. When this happens the files are physically moved from the original folder to the new subfolder (and the original file ceases to exist).

    It sounds like you want a COPY of the file in the New Subfolder, with the copy having a new name. The original file would remain intact in the original folder with the original name.

    Lewis

  21. #21
    Forum Contributor spiwere's Avatar
    Join Date
    01-11-2013
    Location
    IN
    MS-Off Ver
    Excel 2007
    Posts
    410

    Re: Renaming WAV Files in a Folder

    Dear Lewis,

     I'm glad you seemed to have success using my file.
    The results are phenomenal. Please accept my apologies for not supporting with examples. Please see my response below:

    What should the name of the SubFolder be? – It could be today's date. –

     Yes, that will be perfect, just that if the format could be “Renamed Copy - June 6, 2014”.
    Would it be possible to move the files that have exactly the same name before running the final command to a new folder, and keep only 1 “Unique” WAV file for processing the naming?

     A file is considered to be unique if has exactly the same naming convention up to “732914 2014-06-05 08_45_54 2345654321 -_ 1234567892”
     i.e. excluding the file name part, which is “ID_16184365”
    I’ve created the following folders for processing on my desktop:

    1). Main folder name: “My Voice”. Sub-folders within “My Voice”

    a). “WAV Files”. This has dump of all the WAV files
    b). “Duplicate WAV Files”. This is the folder to which all duplicate files should be moved from the “WAV” files folder, leaving only Unique files in WAV Files folder for renaming
    c). “Renamed Copy - June 6, 2014”. This is the folder that should have the copy of the renamed file

    Example:

    Step 1: let’s say all the file (listed below) exist in WAV Files folder
    Step 2: Move all the duplicate files from “WAV Files” to “Duplicate WAV Files” leaving only unique file in the WAV Files folder
    Step 3: Rename and Copy the Unique files in “Renamed Copy - June 6, 2014”. The original unique file should remain intact in the original folder(WAV Files) with the original name.

    Treating files:

    File: 732914 2014-06-05 08_45_54 2345654321 -_ 1234567892 ID_16184365 – Keep it in WAV Files for renaming
    File: 732914 2014-06-05 08_45_54 2345654321 -_ 1234567892 ID_16184367 – Duplicate, please move to Duplicate WAV Files folder

    File: 732922 2014-06-05 09_21_54 2345654321 -_ 1986312457 ID_16004368 – Keep it in WAV Files for renaming
    File: 732922 2014-06-05 09_21_54 2345654321 -_ 1986312457 ID_16024369 – Duplicate, please move to Duplicate WAV Files folder
    File: 732922 2014-06-05 09_21_54 2345654321 -_ 1986312457 ID_16014377 – Duplicate, please move to Duplicate WAV Files folder
    File: 732922 2014-06-05 09_21_54 2345654321 -_ 1986312457 ID_16034379 – Duplicate, please move to Duplicate WAV Files folder

    File: 732913 2014-06-05 13_21_54 2345654321 -_ 1234567890 ID_16184375 – Keep it in WAV Files for renaming
    File: 732913 2014-06-05 13_21_54 2345654321 -_ 1234567890 ID_16184368 – Duplicate, please move to Duplicate WAV Files folder
    File: 732913 2014-06-05 09_22_54 2345654321 -_ 1234567890 ID_16184375 – Keep it in WAV Files for renaming
    File: 732913 2014-06-05 09_22_54 2345654321 -_ 1234567890 ID_16184375 – Duplicate, please move to Duplicate WAV Files folder

    Hope I’ve explained it clearly. Really appreciate your efforts and time to help me out with this!

    Best regards,
    Spi
    Last edited by spiwere; 06-13-2014 at 05:33 AM.

  22. #22
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Renaming WAV Files in a Folder

    Hi Spi,

    This is a fun project to work on. I implemented all your suggestions to the best of my ability. Your file list was very helpful. Please let me know what features you don't like, and I will modify to suit your needs.

    I still have two major concerns which are related:
    a. Attempting to MOVE a 'Duplicate File' to the 'Duplicate Folder', when a copy of the file already exists
    in the Folder. Files can be programmatically DELETED, but I don't like doing it, because with one small
    mistake, very bad things can happen.

    b. Attempting to COPY a 'File' to the 'Daily WAV Files Folder', when a copy of the file already exists
    in the Folder. Similar to a. above.

    There are possible workarounds to both items, including:
    a. Deletion of one of the offending files OR
    b. Renaming a file by adding an appendix at the end of the file name ('A', 'B', 'C', etc.)


    ---------------------
    I added 3 new data entry cells (in case you ever change SubFolder names in the future).
    a. SubFolder 1 for 'WAV files'
    b. SubFolder 2 for 'Duplicate WAV files'
    c. Daily SubFolder Naming Format (contains the rules for changing the 'Daily SubFolder Name'.
    I hope the comments in Cell 'H12' are self-explanatory.

    Try the attached Excel file and the ADDITIONAL simulated .wav files that contain the names of the
    files included in your last post with 2 exceptions due to the following possible inconsistincies I noticed:

    File: 732913 2014-06-05 13_21_54 2345654321 -_ 1234567890 ID_16184375 – Keep it in WAV Files for renaming
    File: 732913 2014-06-05 13_21_54 2345654321 -_ 1234567890 ID_16184368 – Duplicate, please move to Duplicate WAV Files folder
    Since 68 is prior to 75 in file sort order (68 is kept, and 75 becomes the duplicate).

    File: 732913 2014-06-05 09_22_54 2345654321 -_ 1234567890 ID_16184375 – Keep it in WAV Files for renaming
    File: 732913 2014-06-05 09_22_54 2345654321 -_ 1234567890 ID_16184375 – Duplicate, please move to Duplicate WAV Files folder
    Both names are identical - Windows won't allow identical names (75 in second file changed to 76).

    Lewis

  23. #23
    Forum Contributor spiwere's Avatar
    Join Date
    01-11-2013
    Location
    IN
    MS-Off Ver
    Excel 2007
    Posts
    410

    Re: Renaming WAV Files in a Folder

    Dear Lewis,

    First thing first - Thanks a billion Lewis. You are a genius by all means! I’m speechless after seeing your expertise and skills. Wish I had the same!

    
    This is a fun project to work on.  I implemented all your suggestions to the best of my ability.  Your file list was very helpful.  Please let me know what features you don't like, and I will modify to suit your needs.

    Please see my response below:

     I still have two major concerns which are related  (Point A and B)
    I’ll be starting the process afresh daily. A new batch of files will be added to the Master Folder daily, but before doing so I’ll be deleting the files in all sub-folders that were processed the previous day. In this case, the copy of the file won’t be there in any scenario, unless I misunderstood your questions. Please let me know if this does not make sense.

    You were right on the inconsistencies, I had inadvertently copied the names incorrectly. My apologies, but dealing with 2000-5000 of these WAV files daily has got me stumped many a times, which is why I opted to seek assistance.

    Thus far (today and tomorrow being an off) I’ve tested the simulated files, and few others that I dummy created. They all seem to work perfectly. However, I’m sure that once I run this on my original files I may need some bit of tweak - though I hope not!

    May I please seek your permission to run the tests over the next few days (Mon – Wed), before I can confidently say “All is well”, and close this thread as "Solved". I’ll keep you posted.

    All I can say is a very very “Big Thank You”. You are a superman!

    Best,
    Spi
    Last edited by spiwere; 06-15-2014 at 12:55 PM.

  24. #24
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Renaming WAV Files in a Folder

    Hi Spi,

    I'm glad it's working out using simulated files. Even though it might take a while, if I were you, I'd made a backup copy of the real files before running the program the first couple of days. Things always tend to run better, when you're prepared for a disaster.

    I didn't think the concerns I had would be a problem, but I had to bring them up anyway. I always like to be prepared for worst case scenarios. That way they usually never occur.

    Please take your time when testing. If you have any issues (or enhancement requests) now, or any time in the future, please let me know, and I'll do my best to make you happy.

    Lewis

  25. #25
    Forum Contributor spiwere's Avatar
    Join Date
    01-11-2013
    Location
    IN
    MS-Off Ver
    Excel 2007
    Posts
    410

    Re: Renaming WAV Files in a Folder

    Dear Lewis,

    Thanks so much for this magical piece. I’m really excited with the way my tests are going. You are a genius!

     Even though it might take a while, if I were you, I'd made a backup copy of the real files before running the program the first couple of days. Things always tend to run better, when you're prepared for a disaster.
    Yes, I’ll always have a back-up. My files are always downloaded in a zip, and are available in a repository as a back-up to counter any worst case scenarios

    Please take your time when testing. If you have any issues (or enhancement requests) now, or any time in the future, please let me know, and I'll do my best to make you happy.
    Many many thanks. You are a gem! So glad to get connected through this forum. Would it be okay to add you as a friend?

    Best,
    Spi

  26. #26
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Renaming WAV Files in a Folder

    Hi Spi,

    Backups in this establishment. I'm shocked, simply shocked. Great job.

    I'd be happy to have you as a friend. It's good that things seem to be working out.

    Lewis

  27. #27
    Forum Contributor spiwere's Avatar
    Join Date
    01-11-2013
    Location
    IN
    MS-Off Ver
    Excel 2007
    Posts
    410

    Re: Renaming WAV Files in a Folder

     I'd be happy to have you as a friend.  It's good that things seem to be working out.

    Dear Lewis,

    You are a magician (if I may say so)! The solution is way ahead of being termed as “Awesome”. I love it!

    Thanks for simplifying my life. My results have been superbly impressive thus far.

    Once again “A very BIG THANK YOU”. Stay connected and Stay Blessed!

    Regards,
    Spi

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Listing/Renaming Files in a folder from excel
    By Kelshaer in forum Excel Tips
    Replies: 4
    Last Post: 01-23-2013, 11:04 AM
  2. Replies: 1
    Last Post: 01-15-2013, 03:05 AM
  3. Merging excel files + renaming them with folder name + restructuring them
    By BohkAl in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-23-2011, 07:47 AM
  4. Renaming multiple files in a Folder
    By csmithee in forum Excel General
    Replies: 1
    Last Post: 06-11-2009, 02:36 PM
  5. Excel files replicating and renaming in a folder
    By hpum in forum Excel General
    Replies: 0
    Last Post: 07-21-2007, 09:23 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1