Changing File Name

  • Thread starter Thread starter Akash
  • Start date Start date
A

Akash

Hi,

Suppose i have a Folder August 07
Inside there are 50 folders of Different Employees
Under Each folder i have one Excel File with the name of "Format for
the 1st Aug to 10 Aug"

Now what i want is to change the name of the File from "Format for the
1st Aug to 10 Aug" to "Current Time Sheet For 1st Aug to 10th Aug"

How can i do that....

Thanks

Regards
Akash
 
Dim FSO As Object

Sub Folders()
Dim i As Long
Dim sFolder As String

Set FSO = CreateObject("Scripting.FileSystemObject")
SelectFiles "C:\test"

End Sub

'-----------------------------------------------------------------------
Sub SelectFiles(Optional sPath As String)
'-----------------------------------------------------------------------
Dim fldr As Object
Dim Folder As Object
Dim file As Object
Dim Files As Object

Const LookFor As String = "Format for the"
Const ChangeTo As String = "Current Time Sheet For"

Set Folder = FSO.GetFolder(sPath)

Set Files = Folder.Files
For Each file In Files
If file.Type Like "*Excel*" Then
If Left$(file.Name, 14) = LookFor Then
Name file.Path As Replace(file.Path, LookFor, ChangeTo)
End If
End If
Next file

For Each fldr In Folder.Subfolders
SelectFiles fldr.Path
Next

End Sub




--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
Dim FSO As Object

Sub Folders()
Dim i As Long
Dim sFolder As String

Set FSO = CreateObject("Scripting.FileSystemObject")
SelectFiles "C:\test"

End Sub

'-----------------------------------------------------------------------
Sub SelectFiles(Optional sPath As String)
'-----------------------------------------------------------------------
Dim fldr As Object
Dim Folder As Object
Dim file As Object
Dim Files As Object

Const LookFor As String = "Format for the"
Const ChangeTo As String = "Current Time Sheet For"

Set Folder = FSO.GetFolder(sPath)

Set Files = Folder.Files
For Each file In Files
If file.Type Like "*Excel*" Then
If Left$(file.Name, 14) = LookFor Then
Name file.Path As Replace(file.Path, LookFor, ChangeTo)
End If
End If
Next file

For Each fldr In Folder.Subfolders
SelectFiles fldr.Path
Next

End Sub

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

Its not working....
 
Well that is a very illuminating response.

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
Back
Top