Re: (Steve) Iterate files to determine latest and then kill others
- From: Steve Rindsberg <abuse@xxxxxxxxxxxxx>
- Date: Mon, 08 Aug 2005 23:47:31 EDT
I wouldn't trust FileSearch.
Instead, you could do something like this:
Declare an array to hold filenames
Filename = Dir$(filespec)
While Filename <> ""
add the filename to the array
redim array(1 to ubound(array+1) as string
Filename = Dir$
Wend
Sort the array - I think a string sort should work in this case
If not, declare the array as long instead and stuff it with the rightmost
digits of the filenames found coerced to long
Step through the sorted array from 1 to ubound - 1 and kill each file found in
the array, leaving the last one only.
In article <1123549588.915288.316770@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>, C mateland
wrote:
> Steve, thanks ever so much for the ideas on the Kill statement. This
> question is related to the same project. I'm working on a solution, but
> if you have one, feel free to throw it out there. :-)
>
> With the code below, I'm in the middle of a FileSearch where I verify
> the quantity of ppa files the user has in a folder that start with
> "a^main". If he has one, great, I move on. If he has none, no problem,
> got that handled, too.
>
> But if he has more than one, for example he has "a^main0002.ppa" and
> "a^main0014.ppa" and "a^main0022.ppa", I want to delete all but
> "a^main0022.ppa". (I don't know how multiple files could get in like
> that, but it will cause a problem. I have to whittle it down to the one
> highest "main" ppa before I can move on, you see.)
>
> So, I'm trying to code where, when more than one such file is found, it
> will examine the right 4 digits of the names. FWIW, when only one
> "main" file is found, I use the following code elsewhere that
> successfully grabs the name and the version (as integer). Maybe I can
> use like code in the iterations to find the latest of multiple "main"
> files, but I'm having brain-drain trying (although I'll stay at it).
>
> 'Get name of main ppa file
> sPpaMainName = Dir(.FoundFiles(1))
> 'Get version number of main ppa file
> iPpaMainVer = Mid(sPpaMainName, _
> Len(sPpaMainName) - 7, 4)
>
> Here is the file search I'm in where, if >1 "main" files are found,
> I'll have to iterate and keep only the latest.
>
> With Application.FileSearch
> .NewSearch
> .LookIn = sPpaFolder
> .SearchSubFolders = False
> .FileName = "a^main*.ppa"
> .Execute
> iPpaMainQty = .FoundFiles.Count
>
> If iPpaMainQty > 1 Then
> 'CODE: Keep newest file and kill others ???
> End If
>
-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
.
- References:
- (Steve) Iterate files to determine latest and then kill others
- From: c mateland
- (Steve) Iterate files to determine latest and then kill others
- Prev by Date: Re: panning through long photos
- Next by Date: Re: assigning same function to the actions of every picture in a photo album
- Previous by thread: Re: (Steve) Iterate files to determine latest and then kill others
- Next by thread: Text in Flyins piling up
- Index(es):
Relevant Pages
|