473,385 Members | 1,409 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,385 software developers and data experts.

loop through folder and return highest file name found

hi there folks,

I was wondering if I have a folder with the following files in it, can
I return 00012a.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
2 2490
On Oct 18, 7:41 am, dobb...@gov.nl.ca wrote:
hi there folks,

I was wondering if I have a folder with the following files in it, can
I return 00012a.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.
It's really not clear what you're trying to do here. Are you trying
to rename a group of files? Copy a group of files somewhere else?
Copy or rename only certain files meeting certain criteria?

Bruce

Oct 18 '07 #2
On Oct 18, 8:41 am, dobb...@gov.nl.ca wrote:
hi there folks,

I was wondering if I have a folder with the following files in it, can
I return 00012a.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.
What is your REAL objective here? What underlying task are you
attempting to accomplish?

Oct 18 '07 #3

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

Similar topics

13
by: jenny | last post by:
Hi, I am trying to find a VB way that would create a folder on all existing drives - the folder name would be the same on each drive. ie c:\backup, d:\backup, etc. But the folders would only be...
4
by: AndrewM | last post by:
Hello, I have a SUB which has input variables. If I run it once its okay, but I need to include it in a for....next loop. Can this be done ? for i=0 to 100 call mySub(arr(0,i)) next
2
by: John Regan | last post by:
Hello All I am trying to find the owner of a file or folder on our network (Windows 2000 Server) using VB.Net and/or API. so I can search for Folders that don't follow our company's specified...
9
by: Bill Nguyen | last post by:
I need a VB routine to loop thru a select top folder to find all subfolders and list all subfolders/files under each of these subfolders. Any help is greatly appreciated. Bill
6
by: Ritesh Raj Sarraf | last post by:
Hi, Following is the code: def walk_tree_copy(sRepository, sFile, sSourceDir, bFound = None): try: if sRepository is not None: for name in os.listdir(sRepository): path =...
3
by: spamsink42 | last post by:
hello how do i create a dialog to allow the user to choose a folder? i tried FolderBrowserDialog but encountered a couple of problems: - when you specify the starting location (property...
3
by: lostncland | last post by:
I am working on this program. The array has 10 scores. (there is more to this program.) Does the last "for" section make sense? /*Defines a global constant called N throughout the file. ...
3
by: dobbine | last post by:
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 ...
1
by: Cainnech | last post by:
Hi guys, I'm a bit stuck in an infinite loop. What I'm trying to do in the code below is to compare two arrays and if there's an item in array ALGEMEEN that is not in array ITEMS, I want to add it...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.