Re: Logic problem [message #58203 is a reply to message #58201] |
Thu, 17 January 2008 08:51   |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
"Ryan." <rchughes@brutus.uwaterloo.ca> writes:
> Hi All,
>
> I need assistance with the logic of a particular routine to retrieve a
> list of files by date. I have tried a few methods but they haven't
> been successful. I'm posting here to hopefully get some assistance on
> the logic that I'm using. I can't seem to get it correct. Here are
> the details:
>
> I have a directory of folders (As you can see the folder names
> correspond to a time period that overlap):
> 2004-02-19_2004-02-20
> 2004-02-20_2004-02-21
> 2004-02-21_2004-02-25
> 2004-02-25_2004-02-28
> 2004-03-06_2004-03-10
> 2004-03-10_2004-03-13
> ...
>
> Each of these folders contains various files, I am interested in
> obtaining one with a particular extension, say *.SAS (I should note,
> that sometimes this file does not exist within the folder).
>
> I want to have a special routine that given a date (or a start and end
> date) to return the full path of the *.SAS file(s) or if it doesn't
> exist to print out a statement saying it doesn't exist. If the
Assuming that you can convert your file names to numerical values,
which you seem to have done quite well, then you could do a simple
VALUE_LOCATE() to find match-ups.
For example,
;; A list of days from start to finish
RANGE = DATE + DINDGEN(ENDDATE-DATE+1)
;; Which files match the file start date?
;; (NOTE: assumes DIRDATES is ascending order)
II = VALUE_LOCATE(DIRDATES(0,*), RANGE)
;; Keep only those that agree with the file end date.
WH = WHERE(RANGE LT DIRDATES(1,II), CT)
IF CT EQ 0 THEN MESSAGE, 'No match!!!!'
II = II(WH)
;; These are the acceptable directories
II = II(UNIQ(II,SORT(II))) ;; remove duplicates
FOUND_DIRS = DIRS(II)
Good luck,
Craig
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|