Results 1 to 2 of 2
  1. #1
    Lounger
    Join Date
    May 2003
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    File Renamer Database (Access 97 or XP)

    Okay, this is going to be tricky I'm sure. I need a database that will go into a folder specified by the user and rename all files in that folder with the extension specified by the user to a specific format.

    I.E.

    We get text files like this:

    (10-01-02)2Test.txt
    (10-01-02)3Test.txt
    (10-02-02)1Test.txt

    I want it to rename the filesto this:

    Test 10-01-02-2.txt
    Test 10-01-02-3.txt
    Test 10-02-02-1.txt

    I don't know where to begin!

    Anyone have anything even remotely like this that can help get me started? How can I make Access look for a folder? How can I make Access go through the folder and rename every file in that folder with the user specified file type into a user specified format? The user will have good knowledge of Access, so will know how to specify the format and file type in a text box or so.

    If you've gotten this far, I've probably given you a headache! Thanks in advance for your help!

    Vassago

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: File Renamer Database (Access 97 or XP)

    1. <!profile=Don Ceraso>Don Ceraso<!/profile> provided this function that lets the user browse for a folder:

    Public Function BrowseFolder(Optional Title As String = "Select a Folder", Optional RootFolder As Variant) As String
    On Error Resume Next
    BrowseFolder = CreateObject("Shell.Application").BrowseForFolder( 0, Title, 0, RootFolder).Items.Item.Path
    End Function

    This function either returns the path of the selected folder, or an empty string "" if the user clicked Cancel.

    2. You can use the good old Dir function (or the FileSystemObject from the Scripting library) to retrieve file names from a folder. For example:

    Dim strFolder As String
    Dim strFile as String
    Dim strExtension As String
    Dim strNewName As String

    strFolder = BrowseFolder ' function mentioned above
    If strFolder = "" Then Exit Sub

    strExtension = InputBox("Specify extension, e.g. txt")
    If strExtension = "" Then Exit Sub

    strFile = Dir(strFolder & "*." & strExtension)
    Do While Not (strFile = "")
    ' Test for pattern, e.g.
    If InStr(strFile, "Test") > 0 Then
    ' Rename file
    strNewName = "Test " & Mid(strFile, 2, 8) & "-" & Mid(strFile, 11, 1) & "." & strExtension
    Name strFolder & "" & strFile As strNewName
    End If
    ' Next file
    strFile = Dir
    Loop

Posting Permissions

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