ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Renaming Zip files (https://www.excelbanter.com/excel-programming/340043-renaming-zip-files.html)

GEORGIA

Renaming Zip files
 
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

Renaming Zip files
 
Look at the Name statement in VBA's help:



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

GEORGIA

Renaming Zip files
 
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

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

GEORGIA

Renaming Zip files
 
It gave me the error message because i had multiple Zip files. So I only
left one Zip files, it didn't not give me the error message, the code ran
fine..with " Done" message pop up like it suppose to. However, the name did
not rename it.

Also,
How would I go about renaming the multiple zip files?
Thank you!

"Dave Peterson" wrote:

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


Dave Peterson

Renaming Zip files
 
When I used application.filesearch on .zip files, none were returned--I'm not
sure if that's a combination of buggy filesearch in xl2003 or buggy filesearch
in xl2003 with winXP home.

..Zip files look like Folders unless you do something weird (if I remember
correctly).

I like the old Dir function to get the names.

But this version only does one folder--no subfolders. Is that important?

Option Explicit
Sub testme01()

Dim myNames() As String
Dim fCtr As Long
Dim myFile As String
Dim myPath As String
Dim JustBaseName As String

'change to point at the folder to check
myPath = "c:\my documents\excel\test"
If Right(myPath, 1) < "\" Then
myPath = myPath & "\"
End If

myFile = ""
On Error Resume Next
myFile = Dir(myPath & "*.zip")
On Error GoTo 0
If myFile = "" Then
MsgBox "no files found"
Exit Sub
End If

'get the list of files
fCtr = 0
Do While myFile < ""
fCtr = fCtr + 1
ReDim Preserve myNames(1 To fCtr)
myNames(fCtr) = myFile
myFile = Dir()
Loop

If fCtr 0 Then
For fCtr = LBound(myNames) To UBound(myNames)
JustBaseName = Left(myNames(fCtr), Len(myNames(fCtr)) - 4)
Name myPath & myNames(fCtr) _
As myPath & JustBaseName & Format(Date, "ddmmyy") & ".zip"
Next fCtr
End If

End Sub

GEORGIA wrote:

It gave me the error message because i had multiple Zip files. So I only
left one Zip files, it didn't not give me the error message, the code ran
fine..with " Done" message pop up like it suppose to. However, the name did
not rename it.

Also,
How would I go about renaming the multiple zip files?
Thank you!

"Dave Peterson" wrote:

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


--

Dave Peterson

GEORGIA

Renaming Zip files
 
PERFECT! Thank you!

"GEORGIA" wrote:

It gave me the error message because i had multiple Zip files. So I only
left one Zip files, it didn't not give me the error message, the code ran
fine..with " Done" message pop up like it suppose to. However, the name did
not rename it.

Also,
How would I go about renaming the multiple zip files?
Thank you!

"Dave Peterson" wrote:

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



All times are GMT +1. The time now is 07:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com