Finding .jpg code

BENNETT4455
01-20-2008, 07:09 AM
Hi this is my first time here and I am new to VB. I have tryed to construnct a code that finds a .jpg file inside a folder, As the file name changes all the time it is hard to get a lock on. any help appriciated many thanks in advance Bennett


Private Sub Command0_Click()

Dim SEARCHNUMBER As String 'loop string
Dim filename As String 'filename string
'compiling string to renaming and copy
filename = "M:\settings\Desktop\New Folder (3)\" & txtname & ".jpg"
'create loop SEARCHNUMBER = 0
For intNumber = 1578 To 2000
SEARCHNUMBER = SEARCHNUMBER + intNumber
On Error Resume Next
Next intNumber

FileCopy "M:\settings\Desktop\New Folder (3)\" & SEARCHNUMBER & ".jpg", filename


On Error Resume Next
' then delete sorce
Kill "M:\settings\Desktop\New Folder (3)\" & SEARCHNUMBER & ".jpg"

Dim CHKFL As String

' Check if folder exists, first.
If Dir("C:\Dir", vbDirectory) = vbNullString Then
Exit Sub
End If

' Check if file existsCHKFL = Dir$("C:\Dir\File.exe")
If CHKFL = "File.exe" Then
Kill ("C:\Dir\File.exe")
End If


End Sub

eKo
01-23-2008, 06:06 AM
hello and welcome to the forums, i basically understand that your trying to rename the pictures is that correct?

first off your loop is not going to find all the pictures. Because

For intNumber = 1578 To 2000
SEARCHNUMBER = SEARCHNUMBER + intNumber
On Error Resume Next
Next intNumber

your starting the loop at 1578, then next time adding to that 1579 so, instead of searching for 1579 your searching for 3157. if you want to go up by 1 replace

SEARCHNUMBER = SEARCHNUMBER + intNumber

with

SEARCHNUMBER = intNumber

also you need to check if there is a file there to copy, i would put this inside the loop

For intNumber = 1578 To 2000
SEARCHNUMBER = intNumber
On Error Resume Next
' check if picture exists
CHKFL = Dir$("M:\settings\Desktop\New Folder (3)\" & SEARCHNUMBER & ".jpg")
If CHKFL = SEARCHNUMBER & ".jpg" Then
' copy it and delete original
FileCopy "M:\settings\Desktop\New Folder (3)\" & SEARCHNUMBER & ".jpg", filename

Kill "M:\settings\Desktop\New Folder (3)\" & SEARCHNUMBER & ".jpg"
End If
Next intNumber

try that.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum