Extracting patterned filenames from [glob] without a loop - possible?

From: Phil Powell (soazine_at_erols.com)
Date: 12/31/03


Date: 30 Dec 2003 15:05:45 -0800

Consider this code:

set fileList [glob -nocomplain -- /my/directory/*.*]

if {$willArchiveTransferredFiles && [string length $fileList] > 0} {
 # FILTER OUT TO ONLY HAVE FILES ENDING IN _[timestamp] AS THESE ARE
GENERATED BACKUP FILES BY transfer.tcl TO BE ARCHIVED
 set blah [regsub -all
{((/[a-zA-Z0-9\-_\.]+)*[a-zA-Z0-9\-\._%~\+]+_[0-9]+\.[a-zA-Z0-9]+)}
$fileList "\\1 " fileList2]
 puts "blah = $blah"
 set fileList2 [string trim $fileList2]
 puts "fileList2: $fileList2"
}

The [regsub] does not work and I am absolutely unclear as to how to
obtain the correct pattern to make it work.

Bottom line is that I want to get every file name from $fileList that
has this kind of pattern:

/dir1/dir2/.../dirN/filename_1918272728722.[some extension]

The filename will always contain the following:
1) directory
2) alphanumeric filename
3) an underscore separator
4) timestamp
5) .[ext]

Thus far I am unsuccessful at extracting this exact pattern from
$fileList. I am trying very hard to avoid using a loop since the
number of files extracted from [glob] into $fileList could be in the
hundreds and that will horrifically clog processing time on the
production box by doing this.

I want to ensure that this code is as streamlined and clean as well as
fully functional as it should be, but for now it fails and I am unsure
as to how to fix it. Suggestions welcome.

Thanx
Phil



Relevant Pages