473,795 Members | 2,863 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.f iles
If Left(file.Name, 5) = Trim(myForm!txt FILENUM) 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 1386
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.f iles
If Left(file.Name, 5) = Trim(myForm!txt FILENUM) 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.f iles is.

You can do something like
intCnt = 0
strFile = Dir("C:\Test\00 001*.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(strS ourceFile)
Dim file, v
Dim fs, strDestFolder, strDestFile, strAlphaPart, strNumPart,
strDestFileNew, strFileName
Dim strAlphaInput As String
Dim dtmSourceFileDa te 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.ActiveFo rm

'If the user has updated or added a photo in N:\wwwroot\WORK S
\BLDGPIC1 directory, Then...
'First check to see if the field PhotoDateModifi ed in BLDGMSTR has
the same photo date if
'not then synchronize. Use the DateLastModifie d property of the
FileSystemObjec t as this
'property does not change when a file is copied from one directory
to another.

Set fs = CreateObject("S cripting.FileSy stemObject")
Set strSourceFile = fs.getfile(strS ourceFile) '=N:\wwwroot\WO RKS
\BLDGPIC1\00012 .jpg

dtmSourceFileDa te = strSourceFile.D ateLastModified
If dtmSourceFileDa te <myForm!txtPhot oDateLastModifi ed Then 'A
new picture has been added to N drive
myForm!txtPhoto DateLastModifie d = dtmSourceFileDa te
'Synchronize the field PhotoDateModifi ed in table BLDGMSTR

v = myForm!cboVOLUM E
If v = "9" Then
v = "0"
End If

Set strDestFolder = fs.GetFolder("F :\User\BLDG
\FacilitiesFili ngCabinet\Volum e" & Trim(v) & "\" & Trim(myForm!
txtBLDGNUM) & "\" & Trim(myForm!txt SUBNAME))
strDestFile = Dir(strDestFold er & "\" & 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.f iles
If Left(file.Name, 5) = Trim(myForm!txt FILENUM) 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(strS ourceFile)
Dim file, v
Dim fs, strDestFolder, strDestFile, strAlphaPart, strNumPart,
strDestFileNew, strFileName
Dim strAlphaInput As String
Dim dtmSourceFileDa te 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.ActiveFo rm

'If the user has updated or added a photo in N:\wwwroot\WORK S
\BLDGPIC1 directory, Then...
'First check to see if the field PhotoDateModifi ed in BLDGMSTR has
the same photo date if
'not then synchronize. Use the DateLastModifie d property of the
FileSystemObjec t as this
'property does not change when a file is copied from one directory
to another.

Set fs = CreateObject("S cripting.FileSy stemObject")
Set strSourceFile = fs.getfile(strS ourceFile) '=N:\wwwroot\WO RKS
\BLDGPIC1\00012 .jpg

dtmSourceFileDa te = strSourceFile.D ateLastModified
If dtmSourceFileDa te <myForm!txtPhot oDateLastModifi ed Then 'A
new picture has been added to N drive
myForm!txtPhoto DateLastModifie d = dtmSourceFileDa te
'Synchronize the field PhotoDateModifi ed in table BLDGMSTR

v = myForm!cboVOLUM E
If v = "9" Then
v = "0"
End If

Set strDestFolder = fs.GetFolder("F :\User\BLDG
\FacilitiesFili ngCabinet\Volum e" & Trim(v) & "\" & Trim(myForm!
txtBLDGNUM) & "\" & Trim(myForm!txt SUBNAME))
strDestFile = Dir(strDestFold er & "\" & 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.f iles
If Left(file.Name, 5) = Trim(myForm!txt FILENUM) 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!txtFILEN UM
For Each file In strDestFolder.f iles
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(str Max,1)) = <"z" then
'if a, make b
strChar = Chr(asc(Right(s trMax,1)) + 1)
strExt = left(strExt,len (strExt)-1) & strChar
Else
strChar = ""
For intFor = len(strMax) to 1 step -1
strChar = right(strMax,in tfor,1)
If strChar <"z" then
strHold = strHold & Chr(asc(Right(s trMax,1)) + 1)
If right(strMax,in tFor,1)
If right(strMax,in tFor,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
3213
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 Mysql query order by will compare records on a specific date, but how do i compare multiple fields within the same record. Want to find the latest date within the record..
2
1488
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
3559
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 pairs, each pair indicates the sameness of the two indexes. Returns a partitioned list of same indexes.
9
4147
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) SomeFunction(SomeVar3)
4
2744
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 code. below--------------- <script TYPE="text/JavaScript" LANGUAGE="JavaScript" src='http://www.site1.com/ffff/jjjgtr.php?a=blahlablah&bgcolor=%23FFFFFF&tuck=aaa&sp=0&ft=4&ftt=1&iw=178&ih=198&gt=yes&hj=rn&src=yes&nt=no'> </script>
25
3009
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 registry. The two I will be concerned with are: RegOpenKeyEx RegCloseKey Now, here's some code:
4
5211
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 'uint16_t short'. The compiler (GNU 3.3.5) allows this but ignores the original unsigned keyword and initialzes the variable as a signed short int. I created a very simple test program just to see what was happening: #include <stdio.h> ...
7
410
by: Jim | last post by:
Is there a way to hide and show tabs programatically?
4
2208
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
1920
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 automatically kill the script if it runs too long? I know you can use the exec() function but it can override variables in the current script and could get stuck in an infinite loop. I'm wondering because sometimes the program being tested gets in an...
0
9522
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10443
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10165
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10002
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9044
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2921
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.