Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change File Name for all files in a Folder

Status
Not open for further replies.

bajo71

Programmer
Aug 6, 2007
135
US
Hello,

I'm trying to loop through a folder and change all the names(actually the extensions to "txt", but the original extensions vary) This is what I have...

With Application.FileSearch
.LookIn = szDestPath
xFileCount = .FoundFiles.Count

For i = 1 To xFileCount
.FoundFiles.Item(i) = Replace(.FileName, "305", "txt")
Next


Thanks........
 
If this is a one time thing, download ckrename or another mass file renamer.


ck1999
 
Maybe you can modify my code.

Code:
Sub RenameFiles()
'Rename all .tif files to omit the first three characters
'
Dim OldFileName As String, NewFileName As String, FolderName As String
Dim TempDate As String
    FolderName = "C:\Documents and Settings\smills\Desktop\NewFolder\"
    OldFileName = Dir(FolderName & "*.tif", vbDirectory)
'
    Do While OldFileName <> ""
      If Mid(OldFileName, Len(OldFileName) - 3, 4) = ".tif" Then
        NewFileName = Mid(OldFileName, 4, Len(OldFileName) - 3)
        Name FolderName & OldFileName As FolderName & NewFileName
        OldFileName = Dir
      End If
    Loop
End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top