Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
rename all files in a folder
This routine renames the file "old.jpg" with a new 8 digit name consisting
of today's day, hour, minute and second. How can I modify this so it loops through all of the files in that directory and renames them? Sub RenamePIX() Dim x As String, y, z, OldName, NewName x = "C:\Documents and settings\user\my documents\PIX\" y = Format(Date, "dd") z = Format(Time, "hhmmss") OldName = x & "OLD.jpg": NewName = x & y & z & ".jpg" Name OldName As NewName End Sub |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
rename all files in a folder
Hi DIBS
not sure if i'm understanding correctly what you're after as from my reading of your code you have multiple files called OLD.JPG in a single folder which (AFAIK) is impossible and running a macro on multiple files will take less than a second for each file, which means that you could end up with duplicate new file names. Therefore, the code i've written (well modified from some i wrote earlier) assumes that you have multiple jpg files with different names and also appends an index number to the new names (the other ways to do this is to only append an index number if a duplicate name is produced, via error handling ... or to add code that waits a second or two between each iteration). Sub updatefilenames() Dim oldname As String Dim newname As String Dim fname As String Dim pname As String Dim y Dim z fname = "*.jpg" 'filename pname = "C:\Documents and settings\user\my documents\PIX\" 'folder to use Application.ScreenUpdating = False With Application.FileSearch .NewSearch .LookIn = pname .SearchSubFolders = False .Filename = fname 'check to see if any files match the fname If .Execute() 0 Then For i = 1 To .FoundFiles.Count y = Format(Date, "dd") z = Format(Time, "hhmmss") oldname = .FoundFiles(i) newname = pname & y & z & i & ".jpg" Name oldname As newname Next End If End With Application.ScreenUpdating = True End Sub Hope this helps. -- Cheers JulieD julied_ng at hctsReMoVeThIs dot net dot au "DIBS" wrote: This routine renames the file "old.jpg" with a new 8 digit name consisting of today's day, hour, minute and second. How can I modify this so it loops through all of the files in that directory and renames them? Sub RenamePIX() Dim x As String, y, z, OldName, NewName x = "C:\Documents and settings\user\my documents\PIX\" y = Format(Date, "dd") z = Format(Time, "hhmmss") OldName = x & "OLD.jpg": NewName = x & y & z & ".jpg" Name OldName As NewName End Sub |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
rename all files in a folder
Dear Julie,
Thank you so very much. That works beautifully. rgds, DIBS "JulieD" wrote in message ... Hi DIBS not sure if i'm understanding correctly what you're after as from my reading of your code you have multiple files called OLD.JPG in a single folder which (AFAIK) is impossible and running a macro on multiple files will take less than a second for each file, which means that you could end up with duplicate new file names. Therefore, the code i've written (well modified from some i wrote earlier) assumes that you have multiple jpg files with different names and also appends an index number to the new names (the other ways to do this is to only append an index number if a duplicate name is produced, via error handling ... or to add code that waits a second or two between each iteration). Sub updatefilenames() Dim oldname As String Dim newname As String Dim fname As String Dim pname As String Dim y Dim z fname = "*.jpg" 'filename pname = "C:\Documents and settings\user\my documents\PIX\" 'folder to use Application.ScreenUpdating = False With Application.FileSearch .NewSearch .LookIn = pname .SearchSubFolders = False .Filename = fname 'check to see if any files match the fname If .Execute() 0 Then For i = 1 To .FoundFiles.Count y = Format(Date, "dd") z = Format(Time, "hhmmss") oldname = .FoundFiles(i) newname = pname & y & z & i & ".jpg" Name oldname As newname Next End If End With Application.ScreenUpdating = True End Sub Hope this helps. -- Cheers JulieD julied_ng at hctsReMoVeThIs dot net dot au "DIBS" wrote: This routine renames the file "old.jpg" with a new 8 digit name consisting of today's day, hour, minute and second. How can I modify this so it loops through all of the files in that directory and renames them? Sub RenamePIX() Dim x As String, y, z, OldName, NewName x = "C:\Documents and settings\user\my documents\PIX\" y = Format(Date, "dd") z = Format(Time, "hhmmss") OldName = x & "OLD.jpg": NewName = x & y & z & ".jpg" Name OldName As NewName End Sub |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
rename all files in a folder
you're welcome and thanks for letting me know.
-- Cheers JulieD julied_ng at hctsReMoVeThIs dot net dot au "DIBS" wrote: Dear Julie, Thank you so very much. That works beautifully. rgds, DIBS "JulieD" wrote in message ... Hi DIBS not sure if i'm understanding correctly what you're after as from my reading of your code you have multiple files called OLD.JPG in a single folder which (AFAIK) is impossible and running a macro on multiple files will take less than a second for each file, which means that you could end up with duplicate new file names. Therefore, the code i've written (well modified from some i wrote earlier) assumes that you have multiple jpg files with different names and also appends an index number to the new names (the other ways to do this is to only append an index number if a duplicate name is produced, via error handling ... or to add code that waits a second or two between each iteration). Sub updatefilenames() Dim oldname As String Dim newname As String Dim fname As String Dim pname As String Dim y Dim z fname = "*.jpg" 'filename pname = "C:\Documents and settings\user\my documents\PIX\" 'folder to use Application.ScreenUpdating = False With Application.FileSearch .NewSearch .LookIn = pname .SearchSubFolders = False .Filename = fname 'check to see if any files match the fname If .Execute() 0 Then For i = 1 To .FoundFiles.Count y = Format(Date, "dd") z = Format(Time, "hhmmss") oldname = .FoundFiles(i) newname = pname & y & z & i & ".jpg" Name oldname As newname Next End If End With Application.ScreenUpdating = True End Sub Hope this helps. -- Cheers JulieD julied_ng at hctsReMoVeThIs dot net dot au "DIBS" wrote: This routine renames the file "old.jpg" with a new 8 digit name consisting of today's day, hour, minute and second. How can I modify this so it loops through all of the files in that directory and renames them? Sub RenamePIX() Dim x As String, y, z, OldName, NewName x = "C:\Documents and settings\user\my documents\PIX\" y = Format(Date, "dd") z = Format(Time, "hhmmss") OldName = x & "OLD.jpg": NewName = x & y & z & ".jpg" Name OldName As NewName End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Pulling pdf files from general folder to specific folder | Excel Discussion (Misc queries) | |||
How to create a copy of a folder having five files in it, & rename | Excel Worksheet Functions | |||
how can I specific a folder with wildcard criteria and excel will import all the correct files in that folder? | Excel Discussion (Misc queries) | |||
How to copy 30 csv files from a folder to another folder | Excel Programming | |||
rename folder o files with value from inside each wbk | Excel Programming |