Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pulling pdf files from general folder to specific folder [email protected] Excel Discussion (Misc queries) 2 September 8th 09 09:41 PM
How to create a copy of a folder having five files in it, & rename Matthews Excel Worksheet Functions 1 November 7th 06 03:42 PM
how can I specific a folder with wildcard criteria and excel will import all the correct files in that folder? Raven Excel Discussion (Misc queries) 1 January 24th 06 03:28 PM
How to copy 30 csv files from a folder to another folder ddiicc Excel Programming 1 July 17th 05 09:42 AM
rename folder o files with value from inside each wbk Max Bialystock Excel Programming 2 January 2nd 04 09:24 AM


All times are GMT +1. The time now is 04:25 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"