I need to rename files from filename@f{|56r dfyhf.txt to filename.txt. All file names contain a random string that begin with @ with random string up to .ext
Thank for any help.
Janet
Thank for any help.
Janet
[B][U]Original Filename[/U][/B] [B][U]Renamed to
[/U][/B]filename@f{|56rdfyhf.txt filename.txt
AnotherFile.doc [Unchanged]
WorkFile@abc123.xlsx WorkFile.xlsx
Public Function RenameFiles(strFolder as String)
On Error GoTo EH
'Declare the variables you will use
'You will probably need at least two strings:
'One for the name of the old File, one for the new
'You will probably need some sort of Integer pointer...
'The Dir() function will get a list of files, one at a time
'When you set a variable equal to Dir([FolderName]) you
'will get the name of the first file in the folder
'The next time you use Dir()--no arguments--you will get
'the next file name. When Dir() = "", you have run out
'of files. Use this to your advantage
'So....... Find the first file name here:
[Your Code]
'You will want to loop through records at this point
'to determine if we have run out of files
'Find out if your File Name has "@" in it
'An effective Function to use is Instr()
'Instr([FileName], "@") will return the number of
'character in the string the search element is found
'That function returns 0 if it is not found
'So, if you find the "@", then you also have to find
'The extension (usually 3-4 characters, but may be more)
'Several ways to do that--you could use Instr() again
'as long as there are no more "."s in the file name
'So, if you determine that the file name is
'"filename@f{|56rdfyhf.txt" and the "@" is character 9
'and the extension is ".txt" then you must generate
'the new file name to be: "filename.txt"
'Thus, Rename the file (since it is not being "opened"
'This should be relatively easy:
Name [OldFileName] As [NewFileName]
'Now, you need to find the next file in the folder
'Here is where you will loop back through your code
Exit Function
EH:
MsgBox "There was an error renaming the Files! Error: " & _
Err.Desription
Exit Function
End Function
Comment