Re: extracting all but... [message #46304 is a reply to message #46303] |
Sat, 19 November 2005 07:59   |
William Daffer
Messages: 34 Registered: February 1999
|
Member |
|
|
kl_tah@hotmail.com writes:
> Hi All,
>
> I was wondering how I can extract all but a constant string from an
> array of strings?
> basically, I have an array of filenames with a particular directory
> prefixed to each of the filenames like so:
>
> files =
> ['/some/constant/directory/file1','/some/constant/directory/ file2',
> etc.]
>
> and would like to have just an array of the filenames without the
> prefixed directory name so that the result looks like:
>
> files = ['file1', 'file2', etc.]
>
>
> any ideas?
You didn't tell which version of IDL you're using, so I'm going to
assume it's a fairly recent version.
If it's just a matter of removing the path, use File_Basename()
which, like the unix utility `basename', returns the last component
of a path, i.e. the file name itself.
file_basename('/some/constant/directory/file1') == 'file1.'
You don't have to loop over the filenames, just do the whole vector at once.
the_part_you_want=file_basename(files)
If the constant part of path isn't the entire path and you know its
value, you can use STREGEX()
parts = stregex(your_files,'/the/constant/part/(.*)$', $
/extract,/subexp)
the_parts_you_want=parts[1,*]
You might want to 'reform()' that, to make the first dimension go
away.
If the part isn't constant, you're on your own. ;-)
whd
--
PAINTING, n. The art of protecting flat surfaces from the weather and
exposing them to the critic.
Formerly, painting and sculpture were combined in the same work:
the ancients painted their statues. The only present alliance between
the two arts is that the modern painter chisels his patrons.
-- Ambrose Bierce: _The Devil's Dictionary_
|
|
|