comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: extracting all but...
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: extracting all but... [message #46304 is a reply to message #46303] Sat, 19 November 2005 07:59 Go to previous messageGo to previous message
William Daffer is currently offline  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_
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Version control for IDL software
Next Topic: Re: extracting strings between ' '

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 10:33:48 PDT 2025

Total time taken to generate the page: 1.52032 seconds