|
-
April 14th, 2004, 08:44 AM
#1
VBA, What functions do I use to rename files?
Hi All,
Hope everybody had a nice easter. This is the problem:
I have many many filenames in a folder. About half of them have 9:3 filenames (like 123456789.jpg) and the other half has 8:3 filenames (like 12345678.jpg).
I want the 8:3 filenames to become 9:3 filenames, I want to put a zero in front of all the 8:3 filenames to accomplish this.
Now here is the question, what functions do I use to accomplish this? Dir, Name, As, FileListBox? It would be awsome if someone has done this bedore and can post his findings here?
Maybe it's possible with a couple of dos commands? If someone knows how to select 8:3 files that would be great also.
Best regards,
Jasper
Flying is to throw yourself on the ground and miss
-
April 14th, 2004, 08:50 AM
#2
use a pattern like this :
dir "foldername" & "\????????.???"
then use Dir in a loop and rename files :
name file1 as file2
-
April 14th, 2004, 09:42 AM
#3
Hi hscp,
Thank you for your reply. I came with that solution as wel but I a affraid it doesn't work because that commando will also select the 9:3 files. 9:3 files are for example 1~456789.jpg.
But I had a eureka moment and am now able to solve my problem. If you would like to I can explain my actions in more detail.
Best regards,
Jasper
Flying is to throw yourself on the ground and miss
-
April 14th, 2004, 01:20 PM
#4
Hi using eight ???s should return only 8.3 files.
anyway .. Sure I'd like to know your solution
-
April 15th, 2004, 02:06 AM
#5
First I made a tekst file from my dir. Dir *.jpg> C:\temp.txt
then I Imported the tekst file into my db. with fixed positions. Because the filenames were different lenghts I got a table with different filenames like, 123456789, 12345678., 23456789. the point represents the point from the . jpg.
Then I filter out al records without the point. deleted them. At this point I only had 8:3 records left, made an extra field with a zero in front, like 012345678.
Then I wrote a little piece of code.
------------------------------------------------------------------
Dim mAnswer As Integer
Dim Dbs As DAO.Database
Dim Rec As DAO.Recordset
Dim OldName
Dim NewName
Set Dbs = CurrentDb
Set Rec = Dbs.OpenRecordset("test", dbOpenTable)
mantwoord = MsgBox("Rename pictures", vbCritical + vbYesNo + vbDefaultButton2)
If manswer = vbNo Then
DoCmd.Close
Exit Sub
Else
Rec.MoveFirst
GoTo doorlopen
End If
doorlopen:
Do While Not Rec.EOF
On Error GoTo NoRename
OldName = "I:\test\" & Rec("foto1") & ".jpg"
NewName = "I:\test\" & Rec("foto2") & ".jpg"
Name OldName As NewName
Rec.MoveNext
Loop
NoRename:
If Not Rec.EOF Then
Rec.MoveNext
Resume doorlopen
End If
MsgBox ("Pictures are renamed")
DoCmd.Close
------------------------------------------------------------------------
The field Foto1 has the 8:3 filenames and the Foto2 field the 9:3 names.
Hope somebody can use this some day.
Best regards,
Jasper
Flying is to throw yourself on the ground and miss
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|