473,414 Members | 1,688 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

opps! typo error in previous post, loop through and return highest file

hi there folks,

I was wondering if I have a folder with the following files in it,
can
I return 00012ac.jpg?
00012.jpg
00012a.jpg
00012b.jpg
00012c.jpg
right up to ...
00012z.jpg
00012aa.jpg
00012ab.jpg
00012ac.jpg
Here is a snippet of my code:
'Begin filtering files in the directory for FILENUM pattern and parse
out the file name.
For Each file In strDestFolder.files
If Left(file.Name, 5) = Trim(myForm!txtFILENUM) Then
strFileName = Left(file.Name, Len(file.Name) - 4)
lngAlpha = Len(strFileName)
For lngI = lngAlpha To 1 Step -1
'(strFileName) 'This is where i'm stuck
Debug.Print lngAlpha
Debug.Print strFileName
Next lngI
End If
Next file
End If
End If
'Name strInitFile As strDestFile
'FileCopy strSourceFile, strDestFile
Set fs = Nothing
End Sub
Any help or suggestions would be greatly, greatly appreciated.
Is this pattern of a,b,c the best to use? I could probably rename all
the files using 001,002,003 instead.

Oct 18 '07 #1
3 1372
do*****@gov.nl.ca wrote:
hi there folks,

I was wondering if I have a folder with the following files in it,
can
I return 00012ac.jpg?
00012.jpg
00012a.jpg
00012b.jpg
00012c.jpg
right up to ...
00012z.jpg
00012aa.jpg
00012ab.jpg
00012ac.jpg
Here is a snippet of my code:
'Begin filtering files in the directory for FILENUM pattern and parse
out the file name.
For Each file In strDestFolder.files
If Left(file.Name, 5) = Trim(myForm!txtFILENUM) Then
strFileName = Left(file.Name, Len(file.Name) - 4)
lngAlpha = Len(strFileName)
For lngI = lngAlpha To 1 Step -1
'(strFileName) 'This is where i'm stuck
Debug.Print lngAlpha
Debug.Print strFileName
Next lngI
End If
Next file
End If
End If
'Name strInitFile As strDestFile
'FileCopy strSourceFile, strDestFile
Set fs = Nothing
End Sub
Any help or suggestions would be greatly, greatly appreciated.
Is this pattern of a,b,c the best to use? I could probably rename all
the files using 001,002,003 instead.
I don't understand the question completely or what strDestFolder.files is.

You can do something like
intCnt = 0
strFile = Dir("C:\Test\00001*.JPG"
Do while strFile ""
msgbox strFile
intCnt = intCnt + 1
strFile = Dir()
Loop
msgbox "there were " & intCnt " files."

What I don't understand is where you are selecting a specific file like
"00001C.JPG". You could stuff those values into a combo box or into a
table to show the selection I guess. What do you mean "highest file"?
Oct 18 '07 #2
Hi Salad,
If I have a folder with the following files:
00012.jpg
00012a.jpg
00012b.jpg
00012c.jpg

I would like to know how to return 00012c.jpg

I think I need to use the Chr() function to return the ANSI value to
do it but I don't know how
Maybe first Parse out the letter by striping off '00012' and '.jpg'
parts.
Here is more of my code

Sub AutoUpdate(strSourceFile)
Dim file, v
Dim fs, strDestFolder, strDestFile, strAlphaPart, strNumPart,
strDestFileNew, strFileName
Dim strAlphaInput As String
Dim dtmSourceFileDate As Date
Dim myForm As Form
Dim lngI As Long, lngFileName As Long
Dim varFile As Variant
Dim intFileName As Integer
Dim lngAlpha As Long

Set myForm = Screen.ActiveForm

'If the user has updated or added a photo in N:\wwwroot\WORKS
\BLDGPIC1 directory, Then...
'First check to see if the field PhotoDateModified in BLDGMSTR has
the same photo date if
'not then synchronize. Use the DateLastModified property of the
FileSystemObject as this
'property does not change when a file is copied from one directory
to another.

Set fs = CreateObject("Scripting.FileSystemObject")
Set strSourceFile = fs.getfile(strSourceFile) '=N:\wwwroot\WORKS
\BLDGPIC1\00012.jpg

dtmSourceFileDate = strSourceFile.DateLastModified
If dtmSourceFileDate <myForm!txtPhotoDateLastModified Then 'A
new picture has been added to N drive
myForm!txtPhotoDateLastModified = dtmSourceFileDate
'Synchronize the field PhotoDateModified in table BLDGMSTR

v = myForm!cboVOLUME
If v = "9" Then
v = "0"
End If

Set strDestFolder = fs.GetFolder("F:\User\BLDG
\FacilitiesFilingCabinet\Volume" & Trim(v) & "\" & Trim(myForm!
txtBLDGNUM) & "\" & Trim(myForm!txtSUBNAME))
strDestFile = Dir(strDestFolder & "\" & Trim(myForm!
txtPHOTO)) '00012.jpg
'if the destination directory is empty then simply copy the
file
If strDestFile = "" Then
FileCopy strSourceFile, strDestFolder & "\" & Trim(myForm!
txtPHOTO)
Else 'otherwise begin AutoUpdate

'Begin filtering files in the directory for FILENUM pattern and
parse out the file name.
For Each file In strDestFolder.files
If Left(file.Name, 5) = Trim(myForm!txtFILENUM) Then
strFileName = Left(file.Name, Len(file.Name) - 4)
lngAlpha = Len(strFileName)
For lngI = lngAlpha To 1 Step -1
'(strFileName) 'This is where i'm stuck
Debug.Print lngAlpha
Debug.Print strFileName
Next lngI
End If
Next file
End If
End If

'Name strDestFile As strDestFileNew 'Please Ignore
'FileCopy strSourceFile, strDestFile 'Please Ignore

Set myForm = Nothing
Set fs = Nothing
Set strSourceFile = Nothing
Set strDestFolder = Nothing
End Sub

Oct 18 '07 #3
do*****@gov.nl.ca wrote:
Hi Salad,
If I have a folder with the following files:
00012.jpg
00012a.jpg
00012b.jpg
00012c.jpg

I would like to know how to return 00012c.jpg

I think I need to use the Chr() function to return the ANSI value to
do it but I don't know how
Maybe first Parse out the letter by striping off '00012' and '.jpg'
parts.
Here is more of my code

Sub AutoUpdate(strSourceFile)
Dim file, v
Dim fs, strDestFolder, strDestFile, strAlphaPart, strNumPart,
strDestFileNew, strFileName
Dim strAlphaInput As String
Dim dtmSourceFileDate As Date
Dim myForm As Form
Dim lngI As Long, lngFileName As Long
Dim varFile As Variant
Dim intFileName As Integer
Dim lngAlpha As Long

Set myForm = Screen.ActiveForm

'If the user has updated or added a photo in N:\wwwroot\WORKS
\BLDGPIC1 directory, Then...
'First check to see if the field PhotoDateModified in BLDGMSTR has
the same photo date if
'not then synchronize. Use the DateLastModified property of the
FileSystemObject as this
'property does not change when a file is copied from one directory
to another.

Set fs = CreateObject("Scripting.FileSystemObject")
Set strSourceFile = fs.getfile(strSourceFile) '=N:\wwwroot\WORKS
\BLDGPIC1\00012.jpg

dtmSourceFileDate = strSourceFile.DateLastModified
If dtmSourceFileDate <myForm!txtPhotoDateLastModified Then 'A
new picture has been added to N drive
myForm!txtPhotoDateLastModified = dtmSourceFileDate
'Synchronize the field PhotoDateModified in table BLDGMSTR

v = myForm!cboVOLUME
If v = "9" Then
v = "0"
End If

Set strDestFolder = fs.GetFolder("F:\User\BLDG
\FacilitiesFilingCabinet\Volume" & Trim(v) & "\" & Trim(myForm!
txtBLDGNUM) & "\" & Trim(myForm!txtSUBNAME))
strDestFile = Dir(strDestFolder & "\" & Trim(myForm!
txtPHOTO)) '00012.jpg
'if the destination directory is empty then simply copy the
file
If strDestFile = "" Then
FileCopy strSourceFile, strDestFolder & "\" & Trim(myForm!
txtPHOTO)
Else 'otherwise begin AutoUpdate

'Begin filtering files in the directory for FILENUM pattern and
parse out the file name.
For Each file In strDestFolder.files
If Left(file.Name, 5) = Trim(myForm!txtFILENUM) Then
strFileName = Left(file.Name, Len(file.Name) - 4)
lngAlpha = Len(strFileName)
For lngI = lngAlpha To 1 Step -1
'(strFileName) 'This is where i'm stuck
Debug.Print lngAlpha
Debug.Print strFileName
Next lngI
End If
Next file
End If
End If

'Name strDestFile As strDestFileNew 'Please Ignore
'FileCopy strSourceFile, strDestFile 'Please Ignore

Set myForm = Nothing
Set fs = Nothing
Set strSourceFile = Nothing
Set strDestFolder = Nothing
End Sub
Dim lngMax As String
DIm strAlpha As String 'extension
Dim strMax As String
Dim strF As String
Dim strMyForm As String
Dim strChar As String
Dim strNewFile As String
Dim intFor As Integer
Dim strHold As String

strF = file.Name
strMyForm = myForm!txtFILENUM
For Each file In strDestFolder.files
If Left(strF, 5) = Trim(strMyForm) Then
'remove prefix and ".jpg"
strAlpha = mid(strF,6,len(strF)-9)
If strF <"" Then
If Len(strAlpha) Len(strMax) then
'"aa" < "z" so check for len
strMax = strAlpha
Elseif strAlpha strMax then
strMax = strAlpha
Endif
Else
strMax = chr(64) 'first char before "a"
Endif
Endif
'you now have the highest extension. now increment
If LCase(Right(strMax,1)) = <"z" then
'if a, make b
strChar = Chr(asc(Right(strMax,1)) + 1)
strExt = left(strExt,len(strExt)-1) & strChar
Else
strChar = ""
For intFor = len(strMax) to 1 step -1
strChar = right(strMax,intfor,1)
If strChar <"z" then
strHold = strHold & Chr(asc(Right(strMax,1)) + 1)
If right(strMax,intFor,1)
If right(strMax,intFor,1) <"z" then

Next
Endif

endif
strNewFile = Left(strF, 5) & strExt & ".jpg"
msgbox "The old file was " & strF & " and the new is " & strNewFile

Oct 19 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Gleep | last post by:
sorry i didn't explain it correctly before my table is like this example fields: ID name username outcome date1 date2 date3 (etc..) - date15 price1 price2 price3 (etc..) I know that...
2
by: H | last post by:
Ok, so I have this simple code in a file ; var v = new array( 15 ) ; function Init() { for (var i = 0; i < v.length ; i ++) { v = 0; }
41
by: Xah Lee | last post by:
here's another interesting algorithmic exercise, again from part of a larger program in the previous series. Here's the original Perl documentation: =pod merge($pairings) takes a list of...
9
by: Dominic Godin | last post by:
Hi, I have an asp page that does a lot of processing and reports it's finished by printing the word "Success". For example: <% SomeFunction(SomeVar) SomeFunction(SomeVar1) ...
4
by: paul dallaire | last post by:
HI! I want to execute a link witch is in JavaScript, How do we execute this in asp server side if possible? Basically I don't want anyone to see this link in the code view. this is the link...
25
by: JKop | last post by:
Using MSWindows as an example: On MSWindows, there's a thing called the System Registry, which is a really big database that holds all the settings of the OS. There's API's for working with the...
4
by: slougheed | last post by:
I encountered a problem after we had converted our declarations of 'unsigned short int' to uint16_t. In one instance, whoever did the conversion failed to delete the 'short' keyword so we had a...
7
by: Jim | last post by:
Is there a way to hide and show tabs programatically?
4
by: gorgoroth666 | last post by:
hi, is it any possible to override exact font colors in someone elses website ? i want to override all color except black. so, doing it via firefox's color choices not working. it overrides black too.
1
by: elcron | last post by:
Hi, I'm using python 2.5 on Vista and writing a Genetic Program in Python. I was wondering is there a way to run a script from within another one but in sandbox environment? If there is can it...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.