Seperating images with page numbers

chris-uk-lad

Registered User.
Local time
Today, 08:04
Joined
Jul 8, 2008
Messages
271
Hi all,

I am currently moving photos from 1 directory to another via VBA, basically scanned images. Some of the files have page numbers so i was going to do an if statement but not sure how.

The images are e.g
123-1-Malta.jpg
123-2-Malta.jpg
123-13-Malta.jpg
456-1-Cornwall.jpg

Was thinking something like if file name has "###-" in the first 4 digits (# is wildcard?) then move to a specified directory. How would i do this?
 
Last edited:
could you use something like

if isnumeric(left(3,filename)) = true then
'copy the file to dir
end if

Not sure if that's the answer you want
 
would do but theres some images that have full names like 00123456DSC.jpg
 
Not sure what you are trying to achieve.
Do you want to move all images from one file to another or just certain images?
 
Im moving them all into seperate files, but need to distinguish the ones with ###- so i dont mix them ,as shown in the first example

123-1-Malta.jpg
123-2-Malta.jpg
123-13-Malta.jpg
456-1-Cornwall.jpg

i want malta and cornwall in seperate folders
 
why not move them a "word" at a time, rather than trying to do everything at the same time

ie effectively (pseudocode)

Code:
input a searchstring 'eg "cornwall"
input (or pick) the new folder

for each file in directory
   if the word searchstring is in the filename
   move (or copy) the file
   delete (possibly) the original
   {vba name command will move-rename, but will copy to a different drive i think
   end if
next file
 
i understand your point but im seperating every group of files from different trips, so i could have 1 as 666-Cornwall.jpg and one as 12~01~2008 Cornwall.jpg

I know its rather awkward but i just want a degree of accuracy. I imagined it would be simple with a "If left(filename, ####-) kind of thing worked, but i cant get to work XD
 
i understand your point but im seperating every group of files from different trips, so i could have 1 as 666-Cornwall.jpg and one as 12~01~2008 Cornwall.jpg

a) would you want these in separate folders then, or all in one folder

b) how many different sets of data are you trying to manage

i dont use image libraries much, but i think they actually multiply tag the image *eg cornwall, holiday, beach, sea), and then sort/filter the images based on your tags - and the actual file location doesnt matter. Cant you use picasa (free), or photoshop elements (not free) or something similar
 
Hi Chris
I've knocked together some code that may do the job, or at least point you in the right direction.
There is a problem with it though, when creating a folder for your destination. For the examples you provided it will work fine, but if you went to "Costa Del Sol" you'd end up with a folder called Sol, i.e. it works its way backwards through the file name looking for numbers and charcaters like "-" and "/"
You may need to add/remove charcaters depending on the filenames of your jpgs

I hope this is of some help


Private Sub Command0_Click()

Dim strfile As String, strpath As String, strfolder As String, strC As String
Dim i As Integer

'Change to current location of jpgs
strpath = "C:\Me Photos\"

'This line gets name of a jpg in above folder
strfile = Dir$(strpath & "*.jpg")

'Loop until all jpgs have been processed
Do Until strfile = ""
For i = (Len(strfile) - 4) To 1 Step -1
strC = mid(strfile, i, 1)
'You may need to add further characters depending on the results you get
If IsNumeric(strC) = True Or strC = "-" Or strC = "/" Or strC = " " Then
Exit For
End If
Next i

'create a folder name out of the file name
strfolder = mid(strfile, (i + 1), (Len(strfile) - (i + 4))) & "\"

'check if a directory already exists
If Dir(strpath & strfolder, vbDirectory) = vbNullString Then
'create a directory
MkDir (strpath & strfolder)
End If

'move jpg to relevant directory
Name (strpath & strfile) As strpath & strfolder & strfile

'choose next jpg
strfile = Dir$(strpath & "*.jpg")

Loop
'and i'm spent
End Sub
 
Hi, thanks alot for your contribution but i managed to solve this last night, sorry i didnt state this!!

I did a recordset which checked every file within, and an if statement for any that had the first 4 then moved to a specified directory named after the file minus the page number and throw all those relating files inside it.
so something like...

Code:
  For Each f1 In f
        strFile = f1.Name
        If Left(strFile, 7) Like "******-" Then
            currentFile = Right(f1, Len(f1) - posn)
            currentFile = Mid(currentFile, 7, 2)
            *currently working on something to remove the middle 2 characters*
            MkDir strPath "\" & currentFile

Thanks anyway, greatly appreciated :D
 
f is a recordset of all files within the specified directory, and F1 is each individual file as its looped.
 

Users who are viewing this thread

Back
Top Bottom