View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Renaming Zip files

I didn't get that error when I tried the code. (And the code looked fine to
me.)

But I don't like this portion:

CStr(format(FileDateTime(strFilepath), "ddmmyy")) & ".zip"

I think
CStr(format(Date, "ddmmyy")) & ".zip"
or
just
format(Date, "ddmmyy") & ".zip"

would be what you want.

GEORGIA wrote:

ok i got a sample code from someone on this forum...changed it little
Sub Main()
Dim MyPath As String, MyName As String, strfile
MyPath = GetFolder
If MyPath = "" Then Exit Sub
With Application.FileSearch
.NewSearch
.LookIn = MyPath
.SearchSubFolders = True
.Filename = "*.zip"
.FileType = msoFileTypeAllFiles
If .Execute() 1 Then
For Each strfile In Application.FileSearch.FoundFiles
Call RenameFiles(strfile)
Next
End If
End With
MsgBox "Done...", , ":-)"
End Sub

Function GetFolder() As String
Dim ff As Object
Set ff = CreateObject("Shell.Application"). _
BrowseForFolder(0, "please select folder", 0, "N:\File")
If Not ff Is Nothing Then
GetFolder = ff.Items.Item.Path & "\"
Else
GetFolder = ""
End If
End Function

Sub RenameFiles(ByVal strFilepath As String)


Dim strDate As String, OldName As String, NewName As String
OldName = Dir(strFilepath)
NewName = Left(strFilepath, Len(strFilepath) - Len(OldName)) & _
Left(OldName, Len(OldName) - 4) & _
CStr(format(FileDateTime(strFilepath), "ddmmyy")) & ".zip"
Name strFilepath As NewName

End Sub

however, it is giving me an error message @ Sub RenameFile stating
" Wrong number of arguemtns or invalid property assignment".
What does this mean?

Thank you!

"GEORGIA" wrote:

Hi, I download a zip files from our intranet everyday. It comes over like
this:

FL.ZIP
GA.ZIP
CA.ZIP
NY.ZIP

Is there a way to rename those files and add today's date on with vb code?
so it will rename:
FL 091405.ZIP
GA 091405.ZIP
CA 091405.ZIP
NY 091405.ZIP
??
Thank you!


--

Dave Peterson