Re: file_basename(): bug or feature? [message #42767] |
Thu, 24 February 2005 14:08 |
Paul Van Delst[1]
Messages: 1157 Registered: April 2002
|
Senior Member |
|
|
James Kuyper wrote:
> Paul Van Delst wrote:
> ...
>
>> Couldn't you just loop over the types of path separators? (e.g.
>> ['/','\',':',..etc] for the various systems? Are any of the path
>> separators on different systems allowable filename characters on others?
>
>
> Yes, certainly. That's what makes it such a pain. In particular, "\" and
> ":" are allowable filename characters on Unix systems. It's a little
> tricky to create a filename containing a "\" with shell commands,
> because the "\" is interpretted by the shell, unless it's either quoted
> or escaped. Try:
>
> echo hello > \\
> vi "\"
Oof! I see. I couldn't vi the file, but it was created. Wot a pita.
paulv
--
Paul van Delst
CIMSS @ NOAA/NCEP/EMC
|
|
|
Re: file_basename(): bug or feature? [message #42769 is a reply to message #42767] |
Thu, 24 February 2005 13:48  |
James Kuyper
Messages: 425 Registered: March 2000
|
Senior Member |
|
|
Paul Van Delst wrote:
...
> Couldn't you just loop over the types of path separators? (e.g.
> ['/','\',':',..etc] for the various systems? Are any of the path
> separators on different systems allowable filename characters on others?
Yes, certainly. That's what makes it such a pain. In particular, "\" and
":" are allowable filename characters on Unix systems. It's a little
tricky to create a filename containing a "\" with shell commands,
because the "\" is interpretted by the shell, unless it's either quoted
or escaped. Try:
echo hello > \\
vi "\"
|
|
|
Re: file_basename(): bug or feature? [message #42770 is a reply to message #42769] |
Thu, 24 February 2005 13:40  |
Paul Van Delst[1]
Messages: 1157 Registered: April 2002
|
Senior Member |
|
|
David Fanning wrote:
> Benjamin Hornberger writes:
>
>
>> On Unix machines, IDL's file_basename() function doesn't split a path in
>> Windows format (with backslashes). On Windows machines, it splits both
>> (yes, I know, on Windows you can also use both to specify a path). Is
>> this a bug or a feature?
>>
>> Linux:
>>
>> IDL> filename='d:\path\to\file.ex
>> IDL> print,file_basename(filename)
>> d:\path\to\file.ex
>> IDL> filename='d:/path/to/file.ex'
>> IDL> print,file_basename(filename)
>> file.ex
>>
>> Windows:
>>
>> IDL> filename='d:\path\to\file.ex'
>> IDL> print,file_basename(filename)
>> file.ex
>> IDL> filename='d:/path/to/file.ex'
>> IDL> print,file_basename(filename)
>> file.ex
>>
>> I have a situation where a Linux machine has to handle Windows paths,
>> where this is quite annoying ...
>>
>> Any comments?
>
>
> I'm not sure it's a bug OR a feature. More likely the
> sensible way to write the program, given the original
> purpose. :-)
>
> My FSC_BASE_FILENAME program has the same problem,
> simply because I use PATH_SEP to obtain the path
> separator. I think it would be difficult to write
> a generic routine to handle all types of path separators
> properly,
Couldn't you just loop over the types of path separators? (e.g. ['/','\',':',..etc] for
the various systems? Are any of the path separators on different systems allowable
filename characters on others?
paulv
--
Paul van Delst
CIMSS @ NOAA/NCEP/EMC
|
|
|
Re: file_basename(): bug or feature? [message #42771 is a reply to message #42770] |
Thu, 24 February 2005 13:34  |
Benjamin Hornberger
Messages: 258 Registered: March 2004
|
Senior Member |
|
|
David Fanning wrote:
> I think it would be difficult to write
> a generic routine to handle all types of path separators
> properly,
Well, with regular expressions it shouldn't be a big deal. But for the
time being I just convert all Windows paths to forward slashes ...
Benjamin
|
|
|
Re: file_basename(): bug or feature? [message #42772 is a reply to message #42771] |
Thu, 24 February 2005 13:28  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Benjamin Hornberger writes:
> On Unix machines, IDL's file_basename() function doesn't split a path in
> Windows format (with backslashes). On Windows machines, it splits both
> (yes, I know, on Windows you can also use both to specify a path). Is
> this a bug or a feature?
>
> Linux:
>
> IDL> filename='d:\path\to\file.ex
> IDL> print,file_basename(filename)
> d:\path\to\file.ex
> IDL> filename='d:/path/to/file.ex'
> IDL> print,file_basename(filename)
> file.ex
>
> Windows:
>
> IDL> filename='d:\path\to\file.ex'
> IDL> print,file_basename(filename)
> file.ex
> IDL> filename='d:/path/to/file.ex'
> IDL> print,file_basename(filename)
> file.ex
>
> I have a situation where a Linux machine has to handle Windows paths,
> where this is quite annoying ...
>
> Any comments?
I'm not sure it's a bug OR a feature. More likely the
sensible way to write the program, given the original
purpose. :-)
My FSC_BASE_FILENAME program has the same problem,
simply because I use PATH_SEP to obtain the path
separator. I think it would be difficult to write
a generic routine to handle all types of path separators
properly, but you could probably write a pretty good
specific one if you were sure of the types of filenames
you would be getting. I guess FSC_BASE_FILENAME is as
good a place as any to start.
http://www.dfanning.com/programs/fsc_base_filename.pro
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|