Re-name multiple pdfs files by click a button (1 Viewer)

urjudo

Member
Local time
Today, 07:17
Joined
Oct 9, 2020
Messages
67
Hello,
I'm not sure my question should post in the Form section or Module/VBA section but I would like to know if this is even possible to do it. Currently I'm working on a paperless project. We saved documents to a pdf format and the documents saved in a individual date folder. For example: in a date folder 01-02-20, we have 100 pdf documents with the their own order#. they were saved as 00E123456.pdf, 12E456789.pdf, 01E456782.pdf. What I want to do is add the date in front of these pdfs, so they will look like 01-02-20_00E123456.pfd, 01-02-20_12E456789.pdf, 01-02-20_01E456782.pdf. If documents inside the date folder 04-04-20 then they will all have 04-04-20_ in front of them. These folder is currently save in a network folder Z drive but will be soon to move to Sharepoint.
Can I create a form and a button to re-name them? If yes, how do I do that. I have no clue how to start it.

Any help will be great appreciate!
 

arnelgp

error reading drive A:
Local time
Today, 21:17
Joined
May 7, 2009
Messages
11,558
there is a Freeware utility (Bulk Rename Utility) that will do what you want.
on that program, go to the folder, highlight all pdfs.
on section 9 of the program you can "Append the Folder name".
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:17
Joined
Oct 29, 2018
Messages
14,159
Can I create a form and a button to re-name them?
Hi. Yes, you can. But as @arnelgp said, why reinvent the wheel, if a utility is already available?

Just a thought...
 

urjudo

Member
Local time
Today, 07:17
Joined
Oct 9, 2020
Messages
67
I search about Bulk Rename Utility as arnelgp mention, unfortunately my company will not get the license just for that. so I was wondering how I can use Access to do that?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 07:17
Joined
Feb 28, 2001
Messages
19,092
Do some research in this topic: File System Object. Once you know this program well enough, you can give it a folder name and file template including wild cards. Then when you have the Directory object within FSO, you can step through the collection of files in a loop, one at a time, and for every file matching your criteria (which the file template should filter for you), issue a Name As command or use the FSO to issue the rename.
 

arnelgp

error reading drive A:
Local time
Today, 21:17
Joined
May 7, 2009
Messages
11,558
it is a Freeware, no license required. just download and install.
bulk_rename.png
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:17
Joined
Aug 30, 2003
Messages
34,948
it is a Freeware, no license required. just download and install.

OP stated this was for a company, thus the program is not free for them. Clearly shown in your picture.
 

arnelgp

error reading drive A:
Local time
Today, 21:17
Joined
May 7, 2009
Messages
11,558
this is a standalone renamer.
not fully tested.
 

Attachments

  • db_renamer.zip
    46.8 KB · Views: 23

urjudo

Member
Local time
Today, 07:17
Joined
Oct 9, 2020
Messages
67
Attached is the screen shot of how the documents saved
screenshot.png
 
Last edited:

urjudo

Member
Local time
Today, 07:17
Joined
Oct 9, 2020
Messages
67
Attached is my test DB and what I have done but I have couple of questions.
1). I would like to enter the Year, begin date to end date (which is the whole year from 01/01/10 to 12/31/10 for each year), I'm stuck on the Begin date and End date in the code.
2). I tested mine, it seems it keep adding date on few of the documents, like 01-02-10_00E1234567, 01-02-10_01-02-10_00E1234567, 01-02-10_01-02-10_01-02-10_00E1234567. Not sure why.
 

Attachments

  • Re-name.accdb
    692 KB · Views: 24

arnelgp

error reading drive A:
Local time
Today, 21:17
Joined
May 7, 2009
Messages
11,558
modified renamer to include subfolders.
 

Attachments

  • db_renamer.zip
    83.7 KB · Views: 23

moke123

AWF VIP
Local time
Today, 08:17
Joined
Jan 11, 2013
Messages
2,239
2). I tested mine, it seems it keep adding date on few of the documents, like 01-02-10_00E1234567, 01-02-10_01-02-10_00E1234567, 01-02-10_01-02-10_01-02-10_00E1234567. Not sure why.
If this is not a 1 off procedure you will have to test that the file name hasn't been changed or it will keep adding the folder name to the file name.

In this example I use filesystemobject and use the parent folder name as the prefix of the file name. I also test that the name hasn't been changed before changing it. That should fix the problem your having. It also tests for .pdf extension and will only rename pdf's.
 

Attachments

  • fsoRenamer.accdb
    444 KB · Views: 25

urjudo

Member
Local time
Today, 07:17
Joined
Oct 9, 2020
Messages
67
@moke123 & @arnelgp ,
Both of the DB your provide were working great but I forgot to mention that the last thing after I rename the doc is I need to move them to the new location to the folder that is associate with their subfolder inside their own case#. I'm so sorry to realized this now and hope both of you don't get upset with me keep asking questions and help. I'm very appreciated all your time and effort. This is the first time I deal with the paperless project and rally out of idea. Again so sorry and great appreciated!

screen shot is where are these doc look in the new location:
 

Attachments

  • NewLocation.png
    NewLocation.png
    45 KB · Views: 23

moke123

AWF VIP
Local time
Today, 08:17
Joined
Jan 11, 2013
Messages
2,239
If you look at my code you'll notice that it uses fso.MoveFile MF,MT. The MF argument stands for MoveFrom and the MT argument stands for MoveTo. These variables contain the path of the file. In renaming the file I used .FileMove as its the easiest way to rename the file. I just moved the file to the same folder but you dont have to. You can move it anywhere. If you can figure out how to pass the new folder location to the MT variable it will rename it and move it.

Code:
Sub RecursiveRename(fld As String)
    Dim fold As Folder
    Dim fil As File
    Dim fldr As Folder
    Dim MF As String, MT As String


    Dim fso As New FileSystemObject


    Set fldr = fso.GetFolder(fld)


    For Each fold In fldr.SubFolders


        RecursiveRename CStr(fold)


    Next


    For Each fil In fldr.Files


        MF = fil.Path                                                'Move from
        MT = fldr.Path & "\" & fldr.Name & "_" & fil.Name            'Move to


        If UCase(fso.GetExtensionName(fil.Path)) = UCase("PDF") Then  'test for .PDF
            If Left(fil.Name, 8) <> fldr.Name Then
                fso.MoveFile MF, MT                              'renames file because moving it from and to the same folder
            End If
        End If
    Next


    Set fldr = Nothing

End Sub
 
Last edited:

urjudo

Member
Local time
Today, 07:17
Joined
Oct 9, 2020
Messages
67
@moke123 ,
so sorry to bother you, I'm trying to figure out the MT that you mention but unsuccessful. I know you used
Set fldr = fso.GetFolder(fld)
for the current path that I selected, but not sure how I can tell the system my new path.

Thank you for your time
 

urjudo

Member
Local time
Today, 07:17
Joined
Oct 9, 2020
Messages
67
@moke123 ,
I'm not sure if i'm in the right track. Here is the code that I modified. I tested it, it seems work but the file(s) not appear in the New List box.

Code:
Sub RecursiveRename(fld As String)
    Dim fold As Folder
    Dim fil As File
    Dim fldr As Folder
    Dim Newfld As String
    Dim Newfldr As Folder
    Dim MF As String, MT As String

    Dim fso As New FileSystemObject

    Newfld = Environ("UserProfile") & "\Documents\NewCaseDoc\Order"  'new location

    Set fldr = fso.GetFolder(fld)
    Set Newfldr = fso.GetFolder(Newfld)

    For Each fold In fldr.SubFolders

        RecursiveRename CStr(fold)

    Next

    For Each fil In fldr.Files

        MF = fil.Path                                                'Move from
        MT = Newfldr.Path & "\" & fldr.Name & "_" & fil.Name            'Move to
        If UCase(fso.GetExtensionName(fil.Path)) = UCase("PDF") Then  'test for .PDF
            If Left(fil.Name, 8) <> fldr.Name Then
                fso.MoveFile MF, MT                              'renames file because moving it from and to the same folder
            End If
        End If
    Next


    Set fldr = Nothing

End Sub


Thank you!
 
Last edited:

arnelgp

error reading drive A:
Local time
Today, 21:17
Joined
May 7, 2009
Messages
11,558
do you need to move it Without the subfolders?

additional code on my db to Move pdfs, but does not Copy the subfolders.
 

Attachments

  • db_renamer.zip
    45.9 KB · Views: 26

urjudo

Member
Local time
Today, 07:17
Joined
Oct 9, 2020
Messages
67
@arnelgp ,
Yes, I need to move it without the subfolder because the new location already has the subfolder that the files need to move to.

Thank you,
 

arnelgp

error reading drive A:
Local time
Today, 21:17
Joined
May 7, 2009
Messages
11,558
the Bulk Rename Utility i mentioned earlier can do that for you copy or move.
you should try to explore it.
 

Users who are viewing this thread

Top Bottom