File Listings [message #6816] |
Wed, 28 August 1996 00:00  |
Brian C. Ballard
Messages: 3 Registered: August 1996
|
Junior Member |
|
|
Bon Jour,
RSI Tech support can not solve this, can you? My OS is UNIX (Sun Solaris
2.5), but I want my GUI to be portable to the PC.
---- Problem Summary ----
I don't know how to get directory listings under Win32.
---- Here's what I am trying to do ----
My GUI contains two sub-base widgets similar to the PICKFILE widget.
(In fact, I stole some code from PICKFILE to do it.) Each sub-base has:
1. A text widget to type in a file filter (eg *.tif);
2. A list widget for subdirectories (to navigate directories);
3. A list widget for file names (to select a file); and,
4. A text widget (to type in a path/file name).
This allows the user to select files from two independent directories at
the same time. In UNIX, I am spawning an 'ls' command to get the
subdirectories and file names. This works fine in UNIX.
---- Problem Detail ----
My user wants to run the same application on IDL for Windows. For
Windows and Mac OS, PICKFILE calls an undocumented C routine called
OS_PICKFILE which interfaces with the "common" windows dialog for Win32
or Mac OS. I don't want to use this since the user will have to open it
and close it for each file selected, and there is no way to show two
independent OS_PICKFILE widgets inside the same window.
---- Question ----
Does anyone know how to get a simple directory listing (in text format)
under windows? (Like "dir" in good old DOS.)
---- Possible Answer ----
Might I have to use an external C (or whatever) routine to get the file
list? I would REALLY like to stay in IDL for portability reasons.
Any suggestions will be appreciated.
Gracias,
Brian C. Ballard
Albuquerque, NM, USA
E-mail: bballard@orionint.com
WWW : http://www.orionint.com/~bballard/
|
|
|
Re: File Listings [message #6944 is a reply to message #6816] |
Thu, 29 August 1996 00:00  |
kak
Messages: 16 Registered: February 1995
|
Junior Member |
|
|
"Brian C. Ballard" <bballard@orionint.com> writes:
> RSI Tech support can not solve this, can you? My OS is UNIX (Sun Solaris
> 2.5), but I want my GUI to be portable to the PC.
Heh, heh, better ask in this group; it's cheaper anyway...
> ---- Problem Summary ----
> I don't know how to get directory listings under Win32.
I can't believe that RSI's techsupport did not know this or maybe
it's me and I did not get your point.
Just use
dir_entries = findfile('*.*',count=filecount) ; for Windoze
and you get a string array dir_entries with all file and directory
names in the current directory. Keyword count returns the number
of found files.
However, under UNIX the metachars are interpreted different.
I would simply stick with spawning a ls command in this case.
The Windoze common dialog box has another annoying quirk: it's
button label is fixed to "Open". This is confusing in
applications where you want to choose a filename for saving instead
of opening a file.
IDL would better introduce a keyword for OS_PICKFILE to set the
respective button label from outside.
Before constructing your own pickfile widget, I would consult the
searchable list of IDL routines at http://www.lpl.arizona.edu/idl.html
It contains the routines from all publicly available IDL libraries.
Perhaps someone else has already done your work.
Karl
|
|
|
Re: File Listings [message #6950 is a reply to message #6816] |
Thu, 29 August 1996 00:00  |
Brian C. Ballard
Messages: 3 Registered: August 1996
|
Junior Member |
|
|
Bon Jour, autre temp,
This is a summary of what I found out about my original question.
Thanks to Jim Pendletom of RSI (US) and Peter Mason of CSIRO (AU) for
their help.
Ayer, escribi:
> ---- Question ----
> Does anyone know how to get a simple directory listing (in text format)
> under windows? (Like "dir" in good old DOS.)
I feel foolish for missing the FINDFILE function in the manuals. Here's
part of what I ended up writing if anyone cares (UNIX works, Windows not
tested yet):
<begin>
...
'unix': begin
...
;Get the directory listing, send errors to bit bucket
spawn, [ '/bin/sh', '-c', 'ls -1FLa ' +path+ ' 2> /dev/null'], $
junks, count = junkv, /noshell
;Dirs will end in "/", files don't
j = where( strpos( junks, '/') ge 0, junkv)
if ( junkv eq 0) then dirs = "" $
else begin
;Build the dirs list from elements that ended in /
dirs = junks( j)
;Chop the "/" from the end of each element
for i = 0, junkv-1 do $
dirs(i) = strmid( dirs(i), 0, strlen( dirs(i))-1)
endelse
;Build file path/name, take care of root dir special case
if ( path ne '/') then $
junks2 = path + "/" + filt $
else $
junks2 = path + filt
...
end ;case UNIX
'Windows': begin
...
;Get the directory listing
junks = findfile( path + "\" + "*.*")
;Dirs will end in '\', files don't
j = where( strpos( junks, '\') ge 0, junkv)
if (junkv eq 0) then dirs = "" $
else begin
;Build the dirs list from elements that ended in "\"
dirs = junks(j)
;Chop the "\" from the end of each element
for i = 0, junkv-1 do $
dirs(i) = strmid( dirs(i), 0, strlen( dirs(i))-1)
endelse
...
end ; case Windows
...
<end>
NB: path can not end in "/" (unix) or "\" (windows).
Brian C. Ballard
E-mail: bballard@orionint.com
WWW : http://www.orionint.com/~bballard/
|
|
|