Re: returning filename suffix [message #40605] |
Mon, 23 August 2004 09:04  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Tobi writes:
> is there an existing idl routine that returns a filename suffix?
>
> i have chosen a number of files using the DIALOG_PICKFILE() routine
> and now want to do different things depending on the suffix (IMG, JPG,
> GFX ...) of the file chosen.
There is a FILE_DIRNAME function for getting the directory
part of a file path. And a FILE_BASENAME function for getting
the base filename part of a file path. But, oddly I think,
neither gives you the opportunity to get the file extension.
(Although it is certainly not hard to extract the extension
from a base filename.)
So I've written my own function, FSC_BASE_FILENAME, that
can give you the base filename, the directory, and
the file extension, all at once. For example:
IDL> path = 'C:\RSI\David\Catalyst\catcoord__define.pro'
IDL> basename = FSC_BASE_FILENAME(path, Directory=dir, Extension=ext)
IDL> Print, dir
C:\RSI\David\Catalyst\
IDL> Print, basename
catcoord__define
IDL> Print, ext
pro
You can find the program here:
http://www.dfanning.com/programs/fsc_base_filename.pro
I only use this program in interactive programs, so the input
is expected to come from something like Dialog_Pickfile
or Filepath. I haven't tested it on anything else. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: returning filename suffix [message #40687 is a reply to message #40605] |
Tue, 24 August 2004 07:25  |
tbeetz
Messages: 9 Registered: May 2003
|
Junior Member |
|
|
david - thanks for the program! i also found it strange that there is
no routine provided by idl, since they could just return the extension
when they get they strip the filename ... thanks again!
TOBI
|
|
|