;+------------------------------------------------------------- ; NAME: ; mkdatedir ; PURPOSE: ; Make a directory of the form YYYYMMDD (if it doesnt't exist) ; and move files there if the files were last modified on that date. ; CATEGORY: ; Files, Dates ; CALLING SEQUENCE: ; IDL> mkdatedir, path=path, prefix=prefix, ext=ext, date=date ; INPUTS: ; none ; KEYWORD PARAMETERS: ; PATH - directory ; PREFIX - file prefix for deletion ; EXT - file extension for deletion; file search will be path+prefix+'*.'+ext ; DATE - date for search, of form yyyymmdd, e.g., 20050617 (default=TODAY) ; ALL - if set, all files will be moved to the right directory (overrides DATE) ; VERBOSE - if set, will print informational output ; OUTPUTS: ; none ; COMMON BLOCKS: ; NONE ; EXAMPLE: ; IDL> ; NOTES: ; LIMITATIONS ; Only works on Unix/Linux ; MODIFICATION HISTORY: ; 07-Mar-2007 Added keyword all ; 22-Aug-2005 Written by Bill Davis, PPPL ;-------------------------------------------------------------- pro mkdatedir, path=path, prefix=prefix, ext=ext, date=date, $ all=all, verbose=verbose ; date of form 20050617 if n_elements( path ) eq 0 then $ path='/w/nstx.pppl.gov/htdocs/nstx/Software/Diagnostics/SpecFit/' if n_elements( prefix ) eq 0 then $ prefix = 'nstx_mhd_spectrum_' if n_elements( ext ) eq 0 then $ ext = 'pdf' if n_elements( date ) eq 0 then begin ; do for yesterday daysBefore = 1 date = yrmonthday( systime(0) ) year = strmid( date, 0, 4) month = strmid( date, 4,2) day = strmid( date, 6, 2) julianDay = ymd2jd( year, month, day ) julianDay = julianDay -daysbefore jd2ymd, julianDay, year, month, day date = string( year ) + string( month, format='(I2.2)') + string( day, format='(I2.2)') endif date=STRTRIM( date,2 ) searchPath = path+prefix+'*.'+ext files=file_search( searchPath ) if keyword_set( verbose ) then begin print, ' # of files in '+searchPath + ' ='+ STRTRIM( n_elements( files ),2) endif if n_elements( files ) gt 0 then begin checkedDirExist = 0 for i=0,n_elements( files ) -1 do begin struc=file_info( files[i] ) if keyword_set( all ) then date = yrmonthday(systime(0,struc.mtime)) ;;;stop if yrmonthday(systime(0,struc.mtime)) eq date then begin if not checkedDirExist then begin if nwords( file_search( path+date ) ) eq 0 then begin if keyword_set( verbose ) then print, ' > > will create dir '+ path+date file_mkdir, path+date endif checkedDirExist = 1 endif if keyword_set( verbose ) then print, ' will mv '+files[i], path+date+'/' file_move, files[i], path+date+'/' endif endfor endif end