loop through folder and return highest file name found
loop through folder and return highest file name found
am 18.10.2007 14:41:32 von dobbine
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.
Re: loop through folder and return highest file name found
am 18.10.2007 20:52:09 von deluxeinformation
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
Re: loop through folder and return highest file name found
am 18.10.2007 21:55:38 von Davidb
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?
Re: loop through folder and return highest file name found
am 18.10.2007 22:45:39 von lyle
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.
Air Code:
Public Function FirstFileinAlphabeticalOrder$(ByVal Path$)
Dim File$
Path = Path & "\*.*"
Path = Replace(Path, "\\", "\")
FirstFileinAlphabeticalOrder = Dir(Path)
File = Dir()
While Len(File) > 0
If File < FirstFileinAlphabeticalOrder Then _
FirstFileinAlphabeticalOrder = File
File = Dir
Wend
End Function
Sub test()
Debug.Print FirstFileinAlphabeticalOrder("C:\Documents and Settings
\Lyle Fairfield\My Documents\My Pictures\Agawa")
End Sub