Results 1 to 2 of 2
2003-08-11, 21:29 #1
- Join Date
- May 2003
- 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.
We get text files like this:
I want it to rename the filesto this:
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!
2003-08-11, 21:46 #2
- Join Date
- Mar 2002
- Thanked 30 Times in 30 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
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
' Next file
strFile = Dir