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

Home » Public Forums » archive » existing directories
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
existing directories [message #14087] Mon, 25 January 1999 00:00 Go to next message
Martin Schultz is currently offline  Martin Schultz
Messages: 515
Registered: August 1997
Senior Member
Hi,

maybe something is blocking my mind right now, but I just can't think
of a good (platform independent) way to test whether a directory exists
or not. I am trying to write an 'install.pro' routine (not too fancy but
at least with automatic backup of an old version and automatic creation
of the target directory if not there). Actually, since I am spawning
quite a few unix commands anyhow, a good Unix solution would be fine,
too.

BTW: Has anyone written a routine like this before (which is
documented)? What I have in mind (and working in a rudimentary version)
is this:
* create target directory if necessary
or copy all files in target directory into BACKUP<date> directory
* copy all files from a masterdirectory (either by listfile or file
mask) to target directory
or extract them from the RCS system (version control system).

This would be a generic install routine which would come to life by
package specific caller routines (e.g. install_gamap.pro).

Thanks,
Martin.

--
------------------------------------------------------------ -------
Dr. Martin Schultz
Department for Engineering&Applied Sciences, Harvard University
109 Pierce Hall, 29 Oxford St., Cambridge, MA-02138, USA

phone: (617)-496-8318
fax : (617)-495-4551

e-mail: mgs@io.harvard.edu
Internet-homepage: http://www-as.harvard.edu/people/staff/mgs/
------------------------------------------------------------ -------
Re: existing directories [message #14151 is a reply to message #14087] Wed, 27 January 1999 00:00 Go to previous message
rmlongfield is currently offline  rmlongfield
Messages: 68
Registered: August 1998
Member
> Martin Schultz wrote:
>
>> Hi,
>>
>> maybe something is blocking my mind right now, but I just can't think
>> of a good (platform independent) way to test whether a directory exists
>> or not.

Thanks, Martin, for asking your question. I had tried to do this a while ago
using the IDL Pickfile with no success and gave up on it.

I needed to check different archives for data, and if the directory did not
exist , I had to look for it elsewhere.

Thanks also to those who answered. These suggestions will help clean up a
very messy If Block.

Rose

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
Re: existing directories [message #14161 is a reply to message #14087] Tue, 26 January 1999 00:00 Go to previous message
R.Bauer is currently offline  R.Bauer
Messages: 1424
Registered: November 1998
Senior Member
Martin Schultz wrote:

> Hi,
>
> maybe something is blocking my mind right now, but I just can't think
> of a good (platform independent) way to test whether a directory exists
> or not. I am trying to write an 'install.pro' routine (not too fancy but
> at least with automatic backup of an old version and automatic creation
> of the target directory if not there). Actually, since I am spawning
> quite a few unix commands anyhow, a good Unix solution would be fine,
> too.

Dear Martin

is_dir will return 1 if directory exist and 0 if not. It is platfom
independent (AIX, NT tested)

; Copyright (c) 1999, Forschungszentrum Juelich GmbH ICG-1
; All rights reserved.
; Unauthorized reproduction prohibited.
; This software may be used, copied, or redistributed as long as it is not
; sold and this copyright notice is reproduced on each copy made. This
; routine is provided as is without any express or implied warranties
; whatsoever.
;
;+
; NAME:
; is_dir
;
; PURPOSE:
; Test if directory exist
;
; CATEGORY:
; PROG_TOOLS
;
; CALLING SEQUENCE:
; Result = is_dir(path)
;
; INPUTS:
; path: The variable to be tested.
;
; OUTPUTS:
; This function returns 1 if directory exist else it returns 0
;
; EXAMPLE:
; dir='C:\temp'
; PRINT, is_dir(dir)
; -> 1
;
; MODIFICATION HISTORY:
; Written by: R.Bauer , 26.01.99
;-


FUNCTION is_dir,path
errvar=0
CATCH,errvar
IF errvar NE 0 THEN RETURN,0
CD,curr=curr,path
CD,curr
RETURN,1

END





>
>
> BTW: Has anyone written a routine like this before (which is
> documented)? What I have in mind (and working in a rudimentary version)
> is this:
> * create target directory if necessary
> or copy all files in target directory into BACKUP<date> directory
> * copy all files from a masterdirectory (either by listfile or file
> mask) to target directory
> or extract them from the RCS system (version control system).
>
> This would be a generic install routine which would come to life by
> package specific caller routines (e.g. install_gamap.pro).
>
> Thanks,
> Martin.
>

Did you thought on a self installing of an zip/exe/tar file with included
directories?
If you try this way you have to test only if an old version was installed
previously.


Regards

R.Bauer
Re: existing directories [message #14174 is a reply to message #14087] Mon, 25 January 1999 00:00 Go to previous message
David Foster is currently offline  David Foster
Messages: 341
Registered: January 1996
Senior Member
Martin Schultz wrote:
>
> Hi,
>
> maybe something is blocking my mind right now, but I just can't think
> of a good (platform independent) way to test whether a directory exists
> or not. I am trying to write an 'install.pro' routine (not too fancy but
> at least with automatic backup of an old version and automatic creation
> of the target directory if not there). Actually, since I am spawning
> quite a few unix commands anyhow, a good Unix solution would be fine,
> too.

Martin -

Here are two routines that may help. First is a simple routine
that spawns a UNIX test command:

;----------------------------------------------------------- ------------------
;+
; Function VALID_DIR
;
; Function to determine whether string value specifies valid directory.
; Returns 1 if valid, 0 if not.
;-
;----------------------------------------------------------- ------------------

FUNCTION valid_dir, dir

; Go to UNIX and check if directory exists using test command
; Open a new shell to avoid aliases

spawn, ['/bin/sh -c "test -d ' + dir + '" && echo 1'], result

return, keyword_set( result )
END



Here is DIREXIST.PRO which I got from Phil Williams some time ago:


----------- cut here ---------------------------------------------
FUNCTION DirExist, list
;+
; NAME: DIREXIST
;
; PURPOSE: Determine which elements in list are directories.
;
; CATEGORY: File I/O
;
; CALLING SEQUENCE: result = direxist(list)
;
; INPUTS:
; list : a list of files (i.e. the result from list = FINDFILE())
;
; OPTIONAL INPUTS: none
;
; OUTPUTS: An array of the appropriate size. 1 indicates list(i) is a
; directory. 0 indicates that list(i) is a file.
;
; PROCEDURE:
; Get a file list
; IDL> list = findfile()
; IDL> dirs = direxist(list)
; Print which elements in list are directories
; IDL> print,where(dirs eq 1)
; 1 6 14 22
;
; MODIFICATION HISTORY:
; 27 Dec 96 Initial coding. PMW
; Use direxist.pro from David Fanning as a starting point.
; 28 Dec 96 Fixed bug. Now checking last entry in list. PMW
; 30 Dec 96 Fixed bug with last entry check. PMW
;-


; Save the current directory.

CD, Current=currentDirectory
foo = list
;print,'direxist dir = ', currentDirectory
; Use the Catch error handler to catch the case where we
; try to CD to a directory that doesn't exist.

results = intarr(n_elements(list))
i = -1
Catch, error
IF (error NE 0) THEN BEGIN

; Directory must not exist. Return 0.
bar = 0
goto, YIKES
ENDIF

; Try to CD to the directory. If it doesn't exist, an error occurs.

repeat begin
i = i+1
CD, foo(0), current = currentDirectory

; Well, the directory MUST exist if we are here! Change back to
; the current directory and return a 1.
bar = 1

YIKES:
results(i) = bar
CD, currentDirectory
if n_elements(foo) ne 1 then foo = foo(1:n_elements(foo) - 1)
endrep until n_elements(foo) eq 1
CATCH,/cancel

if n_elements(list) eq 1 then return, results
;--- Now do the last entry
i = i + 1

Catch, error
if (error ne 0) then begin

results(i) = 0
goto,done
endif

CD, foo(0), current = currentDirectory

;--- If were here its a directory
results(i) = 1

CD, currentDirectory

done:
RETURN, results
END



--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
David S. Foster Univ. of California, San Diego
Programmer/Analyst Brain Image Analysis Laboratory
foster@bial1.ucsd.edu Department of Psychiatry
(619) 622-5892 8950 Via La Jolla Drive, Suite 2240
La Jolla, CA 92037
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Concurrent CORBA calls
Next Topic: Re: ls and PV-WAVE problem on HP-UX 10.20

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

Current Time: Wed Oct 08 13:31:04 PDT 2025

Total time taken to generate the page: 0.00875 seconds