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

Home » Public Forums » archive » FILE_EXPAND_PATH
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
FILE_EXPAND_PATH [message #35617] Thu, 03 July 2003 09:07 Go to next message
Jonathan Joseph is currently offline  Jonathan Joseph
Messages: 69
Registered: September 1998
Member
I have IDL 5.5 on Windows and 5.6 on Solaris. I am using the
FILE_EXPAND_PATH function, but am not getting the behavior I would
like on the Windows platform. It works well in all cases except if
I pass the null string ''. On the unix version, I get back what I
expect, which is the current working directory. On the Windows
platform I get back garbage: a short string of meaningless
characters.

Does anyone know if this behavior is fixed in 5.6 for windows? Or
is this function undefined for the null string?

Thanks.

-Jonathan
Re: file_expand_path [message #51858 is a reply to message #35617] Thu, 14 December 2006 18:17 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
damonanomad@gmail.com writes:

> I guess that the short answer is that the file_expand_path function
> will not do what I had hoped (give the path of a file in some "unknown"
> sub-directory of my working directory). In looking at the online help
> index some, I think that file_search may be more suited to what I am
> trying to do. However, when I try to use it following one of their
> examples (#6):
>
> Result = FILE_SEARCH('$HOME', '*', /EXPAND_ENVIRONMENT,
> /TEST_DIRECTORY)
>
> Result has nothing in it although there are sub-directories and
> sub-sub-directories in my working directory. Is '$HOME' not the
> working directory in windows?

Yeah, I'm not sure what they are thinking with that
example. $HOME is not a standard Windows environment
variable. Perhaps they mean "this is how you would do
it IF you had defined an environment variable named
$HOME." Hard to say.

I think in general you have to know where you are
when you create a file path. If you are sure the
file is located in a known subdirectory (say IMAGES)
of where you are currently located, you might create
a path to an image file like this:

CD, Current=thisDir
filename = Filepath(Root_Dir=thisDir, SubDir='images', 'test.img')

Programs exist that help with this. PROGRAMROOTDIR, for example:

http://www.dfanning.com/programs/programrootdir.pro

Or, you could create your own IDL system variable:

IDL> DefSysVar, '!HOME', 'C:\RSI\COYOTE\TEST'
IDL> filename = Filepath(Root_Dir=!HOME, SubDir='images', 'test.img')

Anyway, a few ideas.

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: file_expand_path [message #51860 is a reply to message #35617] Thu, 14 December 2006 16:36 Go to previous message
damonanomad is currently offline  damonanomad
Messages: 2
Registered: December 2006
Junior Member
First off, thanks for the fast reply, David. I didn't get back to IDL
until today.

> if your current
> working directory is C:\somewhere, then when you
> execute the function you get this:
>
> IDL> Print, File_Expand_Path('foo.pro')
> C:\somewhere\foo.pro
>
> This is true whether foo.pro exists or not! (This
> is basically the way FILEPATH works, but perhaps the
> name of this function doesn't disappoint you with inflated
> expectations.)

This is a surprising result to me. It appears, then, that
File_expand_path is basically equivalent to "pwd" in linux, with the
exception that it tacks on a file name that may or may not be in that
current working directory. Strange.


> You will have to get into the directory where the file exists
> before you execute the command:
>
> IDL> CD, 'fieldinfo'
> IDL> Print, File_Expand_Path('full28field.table')
> C:\DocSet\MyDoc\IDL\working\FieldInfo\full28field.table
>

I guess that the short answer is that the file_expand_path function
will not do what I had hoped (give the path of a file in some "unknown"
sub-directory of my working directory). In looking at the online help
index some, I think that file_search may be more suited to what I am
trying to do. However, when I try to use it following one of their
examples (#6):

Result = FILE_SEARCH('$HOME', '*', /EXPAND_ENVIRONMENT,
/TEST_DIRECTORY)

Result has nothing in it although there are sub-directories and
sub-sub-directories in my working directory. Is '$HOME' not the
working directory in windows?

Damon
Re: file_expand_path [message #51898 is a reply to message #35617] Tue, 12 December 2006 16:11 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
damonanomad@gmail.com writes:

> I am trying to to use IDL and have run into some a strange behavior
> in 6.2 using file_expand_path. The following lines illustrate what I
> am seeing:
>
> IDL> file_a=file_expand_path('full28field.table')
> IDL> print, file_a
> C:\DocSet\MyDoc\IDL\working\full28field.table
> IDL> print, file_test(file_a)
> 0
> IDL> file_b='C:\DocSet\MyDoc\IDL\working\FieldInfo\full28field.ta ble'
> IDL> print, file_test(file_b)
> 1
>
> As can be seen above, the path that it is returning is not the true
> path of the file but I don't know why it isn't.

Probably because that function doesn't try to determine
the "true path" of the file. It just "builds" a path
from wherever you happen to be located at the moment
you execute the function. That is, if your current
working directory is C:\somewhere, then when you
execute the function you get this:

IDL> Print, File_Expand_Path('foo.pro')
C:\somewhere\foo.pro

This is true whether foo.pro exists or not! (This
is basically the way FILEPATH works, but perhaps the
name of this function doesn't disappoint you with inflated
expectations.)

> The search path that I
> have set in "Preferences" (in addition to default) is
> 'C:\DocSet\MyDoc\IDL' and its sub-directories. (note that
> '\DocSet\MyDoc' = '\Documents and Settings\user\My Documents' in
> reality)
> Any ideas out there why I am running into this problem? Suggestions
> would be greatly appreciated.

You will have to get into the directory where the file exists
before you execute the command:

IDL> CD, 'fieldinfo'
IDL> Print, File_Expand_Path('full28field.table')
C:\DocSet\MyDoc\IDL\working\FieldInfo\full28field.table

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Zipped Files
Next Topic: Capturing a screenshot in IDL

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

Current Time: Wed Oct 08 14:53:44 PDT 2025

Total time taken to generate the page: 0.00445 seconds