Public Sub RenameFiles(ByVal fnFolder As String, fnSrcExtension As String, fnTrgExtension As String)
Dim srcFile As String, lenTrg As String
If Right(fnFolder, 1) <> "\" Then fnFolder = fnFolder & "\"
srcFile = Dir(fnFolder & "*." & fnSrcExtension, vbDirectory)
Do While Not srcFile = vbNullString
Select Case srcFile
Case ".", ".."
Case Else
lenTrg = Right(srcFile, Len(srcFile) - InStrRev(srcFile, ".", -1))
Name fnFolder & srcFile As fnFolder & Left(srcFile, Len(srcFile) - Len(lenTrg)) & fnTrgExtension
End Select
srcFile = Dir
Loop
MsgBox "Mission accomplished"
End Sub
Private Sub Command1_Click()
Call RenameFiles("c:\PICS", "jpg", "txt")
End Sub
S
Main Topics
Browse All Topics





by: amethyst3739Posted on 2004-09-28 at 14:04:29ID: 12174172
Hi Fordraiders,
item)
---------- ---------- ---------- ---------- ---------- ---
You might want to try this:
Private Function RetrieveFiles(s_directory As String, ByRef coll_return_list As Collection)
Dim s_file_list_item As String
Set coll_return_list = New Collection
s_file_list_item = Dir$(s_directory, vbDirectory)
While (Len(s_file_list_item))
If GetAttr(s_directory & s_file_list_item) <> vbDirectory Then
coll_return_list.Add StripFileName(s_file_list_
End If
s_file_list_item = Dir$
Wend
End Function
Private Function StripFileName(s_file As String) As String
Dim n_lastperiod As Integer
n_last_period = InStrRev(s_file, ".")
If n_last_period <> 0 Then
StripFileName = Mid(s_file, 1, n_last_period - 1)
Else
StripFileName = s_file
End If
End Function
'-------------------------
'And then the calling routine could be something like this:
Private Sub Command1_Click()
Dim file_list As Collection
RetrieveFiles "C:\", file_list
End Sub