Page 2 of 4 <1234>
Topic Options
#33461 - 2002-11-26 10:42 PM Re: Copy Based On FileDate
Austin Offline
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
#33462 - 2002-11-26 10:47 PM Re: Copy Based On FileDate
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Have you taken a look at the CleanTempfiles() UDF as I recommended earlier? This UDF si nearly doing what you are looking for, you just need to change it to move files/folders instead of deleting them.
_________________________
There are two types of vessels, submarines and targets.

Top
#33463 - 2002-11-26 10:51 PM Re: Copy Based On FileDate
Austin Offline
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 Offline
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
#33465 - 2002-11-27 04:12 PM Re: Copy Based On FileDate
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
What if a directory with an 'old' date contains a file with a 'new' date? The move should solely be based on the age of the files. Directories will be created when necessary.

[ 27. November 2002, 16:14: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#33466 - 2002-11-27 04:25 PM Re: Copy Based On FileDate
Austin Offline
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
#33467 - 2002-11-27 04:32 PM Re: Copy Based On FileDate
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
let me ask little bit here...
same folder? does that mean that the files are in the main folder or is there subfolders?
if subfolders, does all the data sit in those or is there also in the main?
where you want to move or just rename?
or even just copy the file like backup and leaving it beside the original one?

what is the system to run this on?
what is the kix version?
is this for only one server or for all wksta's?
can I write the code for you?

and so on...
did I ask enough? [Cool]
_________________________
!

download KiXnet

Top
#33468 - 2002-11-27 09:41 PM Re: Copy Based On FileDate
Austin Offline
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 Offline
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 Offline
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.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#33471 - 2002-11-27 10:20 PM Re: Copy Based On FileDate
Austin Offline
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
#33472 - 2002-11-27 10:22 PM Re: Copy Based On FileDate
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
austin, this gives the info but it requires the wksta to be w2k,ME or xp:
code:
$=createobject("shell.application")
$.namespace("C:\Documents and Settings\Lonkero\Työpöytä\KiXforms\BBCodeParser_2").self.modifydate



[ 27. November 2002, 22:25: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
#33473 - 2002-11-27 10:25 PM Re: Copy Based On FileDate
Chris S. Offline
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 Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
I keep forgetting about CreateObject("Scripting.FileSystemObject") [Embarrassed]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#33475 - 2002-11-27 10:29 PM Re: Copy Based On FileDate
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
blaah!
I just wrote mine [Frown]

well, better score though [Wink]
code:
$folder="C:\Documents and Settings\lonkero\Työpöytä\KiXforms"
$ = CreateObject("Scripting.FileSystemObject")
$.getfolder($folder).datelastmodified

_________________________
!

download KiXnet

Top
#33476 - 2002-11-27 10:29 PM Re: Copy Based On FileDate
Howard Bullock Offline
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 ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#33477 - 2002-11-27 10:30 PM Re: Copy Based On FileDate
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
ah, which one it was, create date or mod date?
_________________________
!

download KiXnet

Top
#33478 - 2002-11-27 10:31 PM Re: Copy Based On FileDate
Austin Offline
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 Offline
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
#33480 - 2002-11-27 10:35 PM Re: Copy Based On FileDate
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
austin, I still must ask why you ask for that?
direct copy is much faster than setting the attrib and the copy
_________________________
!

download KiXnet

Top
Page 2 of 4 <1234>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 229 anonymous users online.
Newest Members
BeeEm, min_seow, Audio, Hoschi, Comet
17882 Registered Users

Generated in 0.105 seconds in which 0.041 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org