Page 1 of 1 1
Topic Options
#139967 - 2005-05-19 10:03 AM best way to find old files
jechilt Offline
Starting to like KiXtart

Registered: 2000-12-01
Posts: 102
Loc: Denver Colorado
It never ends that our management wants to implement some kind of new function...

We need to be able to scan a drive for files that have not been accessed for the past 6 months. If not, then zip the file and remove the file just zipped. Zipping the file seems easy enough to do but what we are having a problem with is the best way to find the files last accessed.
We have backups running everyday. The files are touched by the backup process so when we do a scan for files last accessed in the past 1 day, all files show up. We don't think scanning for a last modified date will work because many of us use reference files for information. We seldom change the content so it is possible to have a file that is used everyday but has not been modified for a long time and would then cause the file to be zipped if we queried on the last modified date.
Does anyone have any suggestion how to search for files last accessed by datetime? I am not sure if it is possible but if we could search for a file last accessed and exclude the "user account" from the backup, we could get the info.
Is there any way to do an object call against the files looking for the username that accessed the file?

thanks for any suggestions...
_________________________
John
LM Contractor
One of the 2 dads

Top
#139968 - 2005-05-19 10:07 AM Re: best way to find old files
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
This task sure looks like RoboCopy would handle it for you.

RoboCopy is a FREE utility from Microsoft that can be downloaded from here.

Windows Server 2003 Resource Kit Tools (RoboCopy)

Robust File Copy Utility

Here is a link with a little more information about the utility.

ROBOCOPY.exe (Resource Kit )

I'm sure KiXtart can also do this for you but at a much slower speed and a higher learning curve to complete the script and minimal error control.

Top
#139969 - 2005-05-19 10:37 AM Re: best way to find old files
jechilt Offline
Starting to like KiXtart

Registered: 2000-12-01
Posts: 102
Loc: Denver Colorado
I used robocopy quite a bit in the past. I will take another look at it.

Looks like we can use robocopy to provide a report and then use the report to run in a script to zip the files an then delete the original. Too bad robocopy can't zip before purging!


Edited by jechilt (2005-05-19 10:45 AM)
_________________________
John
LM Contractor
One of the 2 dads

Top
#139970 - 2005-05-19 11:36 AM Re: best way to find old files
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Yes the new version of RoboCopy can check/purge files... but you could also have it output a list of files then parse it and feed it to a zip script.

Here is a zip script post.
http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=60855

And this post uses 7Zip to archive
http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Board=UBB2&Number=135181
 
Good luck, let us know how it goes.
 

Top
#139971 - 2005-05-19 03:04 PM Re: best way to find old files
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Using a couple of ready UDFs, I ran reports on "last accessed" with something like this:
Code:

Break On
$FileArray = DirPlus('Q:\AcctJoint\','/s')
For Each $F in $FileArray
If Right($F,4)='.idf'
$Last = Split(fnGetFileProp($F,'DateLastAccessed'),' ')[0]
'"'$F + '",'+ $Last ?
EndIf
Next

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#139972 - 2005-05-19 03:28 PM Re: best way to find old files
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
Quote:

Using a couple of ready UDFs, I ran reports on "last accessed" with something like this:
Code:

Break On
$FileArray = DirPlus('Q:\AcctJoint\','/s')
For Each $F in $FileArray
If Right($F,4)='.idf'
$Last = Split(fnGetFileProp($F,'DateLastAccessed'),' ')[0]
'"'$F + '",'+ $Last ?
EndIf
Next






Les, mind if i golf a little?

Code:

$FileArray = DirPlus('c:\some folder','/s /a-d /f idf')

For Each $F in $FileArray
$last = split($f.DateLastAccessed,' ')[0]
'"'$F + '",'+ $Last ?
Next



and here is some code taht does a check on date that is older than 6 months...

flipctime()
DIRPlus()

Code:

$FileArray = DirPlus('c:\program files','/s')

For Each $F in $FileArray
$last = split(split($f.DateLastAccessed,' ')[0],"/")
$last = flipctime($last[2]+'/'+$last[0]+'/'+$last[1],"00:00" )

if flipctime(@date,"00:00") - $last >= 15811200 ;183 days
? $f.datelastaccessed + " " + $F.name
endif
Next



Bryce


Edited by Bryce (2005-05-19 03:29 PM)

Top
#139973 - 2005-06-19 12:05 PM Re: best way to find old files
jechilt Offline
Starting to like KiXtart

Registered: 2000-12-01
Posts: 102
Loc: Denver Colorado
hi all...
having some trouble....not sure why I am not getting a read in the array.
here is the snip of putting your pieces together
Code:
 
Break On
;Function DIRPlus()
;
;Author Bryce Lindsay bryce@isorg.net
;
;Action Returns an array containing directory files and folders
;
;Syntax DIRPLUS("PATH","OPTIONS")
;
;Version 2.32
;
;Date Revised 2-10-05
;
;Parameters Path
; Full path To To a folder that you want To Return information on.
; "c:\program files"
;
; OPTIONS
; /S Displays files In specified directory and all subdirectories.
; Use a /S# where # is equal to the subfolder depth that you want to recurse.
;
; /A Displays files with specified attributes.
; attributes D Directories R Read-only files
; H Hidden files A Files ready For archiving
; S System files - Prefix meaning not
;
; /M Apply mask string To filter based on InSTR(), separate Each search string witha a |
;
; /F Return a given File extension like exe log or txt Seperate each extension type with a space
;
;
;Remarks Finaly fixed this UDF For To handle multiple recursions,
; also should have a faster responce time since it is using the FSO
;
; ***Please note that the syntax For version 2.0 of this UDF has changed.***
;
; made some tweeks using feedback from Les! thanks! Also NTDOC!
;
;Returns Returns and array of FSO objects that are equal the file and folder objects of
; the given path. Also returns a @ERROR code For event handling.
;
;Dependencies FSO
;
;KiXtart Ver 4.22
;
;Example(s) $Dir = dirplus("c:\program files") ;returns all files and folders In the "c:\program files" folder
; $Dir = dirplus("c:\program files","/s") ;all fiels and folders including subfolders
; $Dir = dirplus("c:\","/a-d") ;returns only a list of files In the c:\
; $Dir = dirplus("c:\","/ad") ;returns only a list of folders In the c:\
; $Dir = dirplus("c:\program files","/ad /s") ;returns only the folders including all subfolders.
;
; $Dir = dirplus("g:\kix\udf","/s /ad /m dir") ; recursive subfolder search, folders only, using a mask string of "dir"
;
; $desktop = dirplus("%userprofile%\desktop","/a-d")
; For Each $file In $desktop
; ? $file
; ? $file.size
; Next
;
Function DirPlus($path,optional $Options, optional $f, optional $sfflag)
If not vartype($f) DIM $f EndIf
If not vartype($sfflag) DIM $sfflag EndIf

DIM $file, $i, $temp, $item, $ex1, $mask,$mask1,$maskArray,$maskarray1,
$ex2, $code, $CodeWeight, $targetWeight, $weight, $masktrue
DIM $tarray[0]

$ex1 = SetOption(Explicit,on)
$ex2 = SetOption(NoVarsInStrings,on)
$codeWeight = 0

If not Exist($path)
If not Exist($path)
$temp = SetOption(Explicit,$ex1)
$temp = SetOption(NoVarsInStrings,$ex2)
Exit(@ERROR)
EndIf

If not vartype($f)
$f = CreateObject("Scripting.FileSystemObject").getfolder($path)
EndIf
If @ERROR
$temp = SetOption(Explicit,$ex1)
$temp = SetOption(NoVarsInStrings,$ex2)
Exit(@ERROR)
EndIf

For Each $temp In Split($options,"/")
$temp=Trim($temp)
Select
Case left($temp,1) = "s"
If not vartype($sfflag)
If Val(right($temp,-1)) = 0
$sfflag = -1
Else
$sfflag = Val(right($temp,-1))
EndIf
EndIf
Case Left($temp,1) = "a"
Select
Case Right($temp,-1)="d"
$codeWeight = $codeWeight + 1
$temp = "if $file.type = 'File Folder' "
Case Right($temp,-1)="-d"
$codeWeight = $codeWeight + 1
$temp = "if $file.type <> 'File Folder' "
Case Right($temp,-1)="s"
$codeWeight = $codeWeight + 1
$temp = "if $file.attributes & 4 "
Case Right($temp,-1)="-s"
$codeWeight = $codeWeight + 1
$temp = "if ($file.attributes & 4)=0 "
Case Right($temp,-1)="h"
$codeWeight = $codeWeight + 1
$temp = "if $file.attributes & 2 "
Case Right($temp,-1)="-h"
$codeWeight = $codeWeight + 1
$temp = "if ($file.attributes & 2)=0 "
Case Right($temp,-1)="r"
$codeWeight = $codeWeight + 1
$temp = "if $file.attributes & 1 "
Case Right($temp,-1)="-r"
$codeWeight = $codeWeight + 1
$temp = "if ($file.attributes & 1)=0 "
Case Right($temp,-1)="a"
$codeWeight = $codeWeight + 1
$temp = "if $file.attributes & 32 "
Case Right($temp,-1)="-a"
$codeWeight = $codeWeight + 1
$temp = "if ($file.attributes & 32)=0 "
EndSelect
$code = $temp + "$weight=$weight+1 endif" +@CRLF + $code

Case Left($temp,1) = "m"
$maskarray = Split(Right($temp,-2),"|")
$codeweight = $codeweight + 1
$code = "$masktrue=0 for Each $mask in $maskarray if instr($file.name,$mask) $masktrue=1 " +
"EndIf Next If $masktrue $weight=$weight+1 endif" + @CRLF +$code
Case Left($temp,1) = "f"
$maskarray1 = Split(Right($temp,-2)," ")
$codeweight = $codeweight + 1
$code = "$masktrue=0 for Each $mask1 in $maskarray1 if substr($file.name,Instrrev($file.name,'.')+1)" +
"=$mask1 $masktrue=1 EndIf Next If $masktrue $weight=$weight+1 endif" + @CRLF +$code

EndSelect
Next
$code = "$weight = 0 $targetWeight = " + $codeweight + @CRLF + $code
$code = $code + "if $weight = $targetweight Exit(1) endif"

For Each $file In $f.subfolders
If Execute($code)
$tarray[$i] = $file
$i = $i + 1
ReDIM preserve $tarray[$i]
EndIf
If $sfflag
$temp = dirplus($file,$options,$file,$sfflag-1)
For Each $item In $temp
$tarray[$i] = $item
$i = $i + 1
ReDIM preserve $tarray[$i]
Next
EndIf
Next
For Each $file In $f.files
If Execute($code)
$tarray[$i] = $file
$i = $i + 1

ReDIM preserve $tarray[$i]
EndIf
Next

If $i
ReDIM preserve $tarray[$i-1]
$i=0
Else
$tarray = 0
EndIf

$dirplus = $tarray
$temp = SetOption(Explicit,$ex1)
$temp = SetOption(NoVarsInStrings,$ex2)
Exit(@ERROR)
EndFunction

;FUNCTION FlipcTime()
;
;ACTION Converts a Kixtart format date/time into a cTime time
;
;AUTHOR Bryce Lindsay
;
;VERSION 1.0 first publish
; 1.1 removed dependencies
; 1.2 added Time Zone support
;
;KIXTART 4.12+
;
;SYNTAX RETCODE = FLIPCTIME(DATE,TIME,[TIME ZONE])
;
;PARAMETERS DATE
; Date in YYYY/MM/DD
;
; TIME
; Time in HH:MM[:SS]
;
; Optional ZIME ZONE
; the timezone taht you want to adjust for.
;
;RETURN the given date/time in number of seconds that have passed since 1970/01/01 00:00:00
;
;REMARKS See this thread for original idea
; http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=80863
; Also know as UNIX time.
; this will error out for dates that are past January 19, 2038 the y2k38 bug!!
;
;DEPENDENCIES None
;
; ;give the Epoc time for the central time zone in the US(-6)
;EXAMPLE $return = FlipcTime("2004/07/08","14:45:23",-6)
;


$FileArray = DirPlus('c:\program files','/s')
;wont run unless I dim $F
Dim $F
For Each $F in $FileArray
If Right($F,4)='.idf'
$Last = Split(fnGetFileProp($F,'DateLastAccessed'),' ')[0]
'"'$F + '",'+ $Last ?
EndIf
Next



Nothing is returned. When I run with debug, when it gets to the For Each, it immediately goes to the end, as if it did not read anything.
any suggestions?
_________________________
John
LM Contractor
One of the 2 dads

Top
#139974 - 2005-06-19 12:35 PM Re: best way to find old files
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Confirmed something wrong with Bryce's current version of the DirPlus UDF.

Even using a basic example and the most current version posted I don't get anything back either.

I think the NoVarInStrings and Explicit method used in the UDF is messing with it, since it tells me that the example var is not dimmed even though I never said to use explicit.

Bryce... please take a look at your UDFs - it's late here 03:30 so time to hit the sack otherwise I'd try to debug it some myself.

 

Top
#139975 - 2005-06-19 03:15 PM Re: best way to find old files
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I think the UDF is exiting early and not restoring the SetOption. Try putting a trailing hack on the path.
$FileArray = DirPlus('c:\program files\','/s')

The UDF can also include a filter so you need not check for .idf and it will return the FSO COM handle so you can access the prop directly without another UDF.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#139976 - 2005-06-19 09:38 PM Re: best way to find old files
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Tried messing with the options some, but so far no go. This produces nothing.

Code:
Break On
Dim $test,$file
$test = dirplus("c:\","/a-d")
For Each $file In $test
$file ?
$file.size ?
Next


 
 

Top
#139977 - 2005-06-20 06:06 PM Re: best way to find old files
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
found the bug in DIRPlus get the latest post 2.33 please. Sorry about that, I was fixing another bug that was happeneing with the explicit ON stuff, and a typo on my part put in another.

Code:

$FileArray = DirPlus('c:\program files','/s /f idf')
;wont run unless I dim $F
For Each $F In $FileArray
$Last = $f.DateLastAccessed
'"'$F + '",'+ $Last ?
Next



Edited by Bryce (2005-06-20 06:06 PM)

Top
#139978 - 2005-07-02 08:08 AM Re: best way to find old files
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Slow as heck, but I can confirm DirPlus now works again.

Thanks Bryce
 

Top
Page 1 of 1 1


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

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.06 seconds in which 0.027 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