Testing folder for a value

Super Suarez

Registered User.
Local time
Yesterday, 21:51
Joined
Jul 10, 2013
Messages
36
Hi,

This code below works, but alot of what it does is unnecessary. I have a directory structure named 1000-2000, 2001-3000, 3001 - 4000 etc and within that is the individual folders 1000, 1001, 1002 etc


How do I test to search top level folder thats no larger than correctNum to then test the subfolder for correctNum? I've looked at instr and a few other funtions, but can't find a solution. Below is what I have now, it works but I know it searches everything and that's not correct

Dim filesys
Dim Subdir
Dim folder
Set filesys = CreateObject("Scripting.FileSystemObject")
Dim oDir
Dim bDir
CorrectNum = Serial.Value
If IsNull(PumpNum) Then GoTo function_finish:
searchfolder = "C:\archive temp"
pfile = False
Set oDir = filesys.GetFolder(searchfolder)
For Each Subdir In oDir.SubFolders
Set bDir = filesys.GetFolder(Subdir)
For Each folder In bDir.SubFolders
If InStr(1, folder, CorrectNum) > 0 Then pfile = True
If InStr(1, folder, CorrectNum) > 0 Then GoTo function_end:
Next folder
Next Subdir
function_end:
If pfile = True Then MsgBox ("good")
If pfile = True Then Shell "Explorer.exe /n,/e," & folder, vbNormalFocus
function_finish:
If IsNull(PNum) Then MsgBox ("no serial num!")

Appreciate your time
 
given a file x (eg 2005)

the folder that holds this file is called 2005

the parent folder is given by (x\1000 * 1000 & "-" & (x\1000+1)*1000)



Code:
Function getfolder(x As Long) As String
getfolder = "\" & ((x \ 1000) * 1000 & "-" & (((x \ 1000) + 1) * 1000)) & "\" & x
End Function
 
I was hoping for functionality that would test for > than beginning of the folder name (first sixcharacters) and < last six charaters.

I was generalising on the folder structure naming convention. It goes something like this 833300-833399, 833400-833499 etc and going back. it's pretty big
 
my solution works generically for any folder name. have you tried it?

try changing the 1000 to 100 for the new scenario you mention.
 

Users who are viewing this thread

Back
Top Bottom