#33461 - 2002-11-26 10:42 PM
Re: Copy Based On FileDate
|
Austin
Seasoned Scripter
Registered: 2002-01-24
Posts: 439
|
I can use enumdir() for this but how can I mask it to where I am only getting directory names not file names as well?
Maybe different udf is needed?
Thanks
_________________________
Austin Henderson
|
Top
|
|
|
|
#33463 - 2002-11-26 10:51 PM
Re: Copy Based On FileDate
|
Austin
Seasoned Scripter
Registered: 2002-01-24
Posts: 439
|
Sure did... was wondering if it woudl be better to clear archive bit for an entire directory then process and set that archive bit and then move files using xcopy or to just move them individually using the kix copy?
Thanks
_________________________
Austin Henderson
|
Top
|
|
|
|
#33464 - 2002-11-27 03:59 PM
Re: Copy Based On FileDate
|
Austin
Seasoned Scripter
Registered: 2002-01-24
Posts: 439
|
Well the cleantempfiles will not work.. like an idiot I modified it as seen below but only to realize it only works at the file level because it is using GetFileTime() which does not work on directories! Any thoughts now...
What I need to to is move directories that are a certain age out to another location.
Thanks
code:
;FUNCTION CleanTempFiles ; ;AUTHOR Jens Meyer (sealeopard@usa.net) ; ;VERSION 1.1 ; ;ACTION Cleans up the temporary directory ; ;SYNTAX CLEANTEMPFILES(ACTION,DIRECTORY,Optional DESTINATION,FILTER,DAYS) ; ;PARAMETERS ACTION ; Required switch that controls the action of the UDF ; 1-Deletes files ; 2-Moves files ; ; DIRECTORY ; Required string/array containing the directory(s) to be cleaned\ ; ; DESTINATION ; OPTIONAL String containing the directory to which files will be moved ; ; FILTER ; Required string/array containing file filters for deletables files/folders, wildcards are supported ; ; DAYS ; Required integer indicating how old a file must be before it is deleted ; ;REMARKS The function will recursively delete all empty subdirectories and files ; Requires the global variable $VERBOSE (true for verbose output) ; ;DEPENDENCIES FULLFILE() @ http://kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=12&t=000028 ; DATEMATH() @ http://kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=12&t=000102 ; DISPLAYTEXT() @ http://kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=12&t=000036 ; ;RETURNS 0 if successful, otherwise error code ; 1000 If invalid action defined ; 1001 If destination does not exist ; ; ;EXAMPLE $retcode=cleantempfiles('c:\temp','*.TMP',7) ; ;KIXTART BBS http://kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=12&t=000103 ; CALL @ScriptDir\udf\DateMath.udf CALL @ScriptDir\udf\DisplayText.udf CALL @ScriptDir\udf\FullFile.udf function cleantempfiles($action, $directories, optional $destination, $filter, $olderas) Dim $retcode, $filetime, $timediff, $filename, $filefilter, $tempdir
if $action=2 if exist ($destination)=0 ?"CHECK" @ERROR=1001 goto ERCOND endif endif $olderas=val($olderas) if $olderas<0 $olderas=0 endif
if vartype($directories)<8192 dim $tmp[0] $tmp[0]=$directories $directories=$tmp endif if vartype($filter)<8192 dim $tmp[0] $tmp[0]=$filter $filter=$tmp endif
for each $tempdir in $directories if $tempdir<>'' and exist($tempdir) for each $filefilter in $filter if $VERBOSE $retcode=displaytext('Filtering '+$tempdir+' for '+$filefilter) endif $filefilter=fullfile($tempdir,$filefilter) $filename=dir($filefilter,1) While $filename<>'' and @ERROR = 0 if $filename<>'.' and $filename<>'..' $filename=fullfile($tempdir,$filename) if exist($filename) $filetime=left(getfiletime($filename),10) $timediff=datemath(@DATE,$filetime) if $VERBOSE $retcode=displaytext('File '+$filename+' dated '+$filetime+' is '+$timediff+' days old') endif if $timediff>$olderas if getfileattr($filename) & 16 $retcode=cleantempfiles($filename,$olderas) $retcode=setfileattr($filename,128) select case $action = 1 ;rd $filename ?"Removing directory: "+$filename if $VERBOSE $retcode=displaytext('Deleting obsolete directory '+$filename) endif case $action = 2 ?"Moving directory: "+$filename if $VERBOSE $retcode=displaytext('Moving obsolete directory '+$filename) endif case 1 @ERROR=1000 GOTO ERCOND endselect
if $VERBOSE $retcode=displaytext('Deleting obsolete directory '+$filename) endif else $retcode=setfileattr($filename,128) select case $action = 1 ;del $filename ?"Removing file: "+$filename if $VERBOSE $retcode=displaytext('Deleting obsolete file '+$filename) endif case $action = 2 ;copy "$filename", "$Destination" ?"Moving file: "+$filename if $VERBOSE $retcode=displaytext('Moving obsolete file '+$filename) endif case 1 @ERROR=1000 GOTO ERCOND
endselect endif endif endif endif $filename=Dir('',1) loop next endif next :ERCOND $cleantempfiles=@ERROR endfunction
_________________________
Austin Henderson
|
Top
|
|
|
|
#33466 - 2002-11-27 04:25 PM
Re: Copy Based On FileDate
|
Austin
Seasoned Scripter
Registered: 2002-01-24
Posts: 439
|
Not in this particular case.. it is working in conjunction with a scrtipt that I wrote to move mail out of my exchange journal mailbox... it does so every night.. I suppose I could check the date of the file in the directory but I need it to move the files inside the folder.. ie the folder name has to stay the same.. think I will be starting from scratch on this one?
_________________________
Austin Henderson
|
Top
|
|
|
|
#33468 - 2002-11-27 09:41 PM
Re: Copy Based On FileDate
|
Austin
Seasoned Scripter
Registered: 2002-01-24
Posts: 439
|
; )
THe deal is that I have a kix script that utilized exmerge.exe to move mail out of my mail server on a nightly basis into pst files. These pst file are put into individual folders that contain a log file and the pst file only. I will be running this on an NT4 box and can run any version of kix needed. What I want to do is move folders to a different location based on their date. That other location will go to tape. So I will move folders (and data contained within them) out of the parent folder into another folder that are older than x days old.
I was working toward a solution but I was not aware that the getfiletime only worked on files.. I thought it worked on directories as well. At any rate thanks for the help.
_________________________
Austin Henderson
|
Top
|
|
|
|
#33469 - 2002-11-27 10:04 PM
Re: Copy Based On FileDate
|
Austin
Seasoned Scripter
Registered: 2002-01-24
Posts: 439
|
Same deal with GetFileAge()
Only works for files... hence the title. I suppose what I need to do is enum the dir and check the age of each file.. if that file is older than the days passed to it...then move it but I will need to create the dir strucute in the copy to path.. any thoughts?
_________________________
Austin Henderson
|
Top
|
|
|
|
#33470 - 2002-11-27 10:16 PM
Re: Copy Based On FileDate
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I can propably send you a Perl program that will determine the age of a directory in days (based on the time the program was started). The age on my W2K computer seems to be the last time the content of the directory was modified.
|
Top
|
|
|
|
#33471 - 2002-11-27 10:20 PM
Re: Copy Based On FileDate
|
Austin
Seasoned Scripter
Registered: 2002-01-24
Posts: 439
|
Well considering I dont know that much about PERL I am not sure if I could work it or not.. ; )
I tried GetFileTime().. it doesnt work on directories either... I wouldnt even know how to go about getting the date and time of a directory.. other than to shell out... do a dir/A:D.. write it to a file then bring it back in and parse it...
Thoughts?
_________________________
Austin Henderson
|
Top
|
|
|
|
#33473 - 2002-11-27 10:25 PM
Re: Copy Based On FileDate
|
Chris S.
MM club member
   
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
Howsabout this...
code:
$fso = CreateObject("Scripting.FileSystemObject") $f = $fso.GetFolder(C:\Archive) "Created: " + $f.DateCreated
|
Top
|
|
|
|
#33474 - 2002-11-27 10:27 PM
Re: Copy Based On FileDate
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I keep forgetting about CreateObject("Scripting.FileSystemObject")
|
Top
|
|
|
|
#33476 - 2002-11-27 10:29 PM
Re: Copy Based On FileDate
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
since his directories most likely keep changing A loop through an array of exisiting directory names and variable substitution is probably in order.
{edit} http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=12;t=000296 [ 27. November 2002, 22:33: Message edited by: Howard Bullock ]
|
Top
|
|
|
|
#33478 - 2002-11-27 10:31 PM
Re: Copy Based On FileDate
|
Austin
Seasoned Scripter
Registered: 2002-01-24
Posts: 439
|
One word for you Brilliance...
_________________________
Austin Henderson
|
Top
|
|
|
|
#33479 - 2002-11-27 10:33 PM
Re: Copy Based On FileDate
|
Austin
Seasoned Scripter
Registered: 2002-01-24
Posts: 439
|
Is it possible to set and archive bit on a directory and files contained withing with a single step?
Thanks
_________________________
Austin Henderson
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 229 anonymous users online.
|
|
|