#125775 - 2004-08-28 04:56 AM
Re: Get the date a file was last accessed
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11634
Loc: Space
|
Hello Cybex and Welcome to KORG
We have UDFs for such, you could also have the new version of RoboCopy from Microsoft tell you that as well.
fnGetFileProp() - Uses FSO to retrieve file properties
http://www.kixhelp.com/udfs/udf/83404.htm
|
|
Top
|
|
|
|
#125778 - 2004-08-28 08:33 PM
Re: Get the date a file was last accessed
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11634
Loc: Space
|
Well with the help of Mr_Jooel and some UDF power, here is an example of doing this.
You can get the UDFs from the board, but I'll post the full thing here to make it easier to copy and test.
Code:
Break On
Dim $SO
$SO=SetOption('Explicit','On')
Dim $HKLMAppPaths,$sFile,$LADate,$TimeDiff
$HKLMAppPaths='HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths'
$sFile=Trim(ReadValue($HKLMAppPaths + '\powerpnt.exe',''))
$LADate=Split(Trim(Join(Split(fnGetFileProp($sFile,DateLastAccessed),""),"",1)),"/")
$LADate=$LADate[2]+"/"+Right("0"+$LADate[0],2)+"/"+Right("0"+$LADate[1],2)
$TimeDiff=DateCalc(@DATE,$LADate)
If $TimeDiff > 0 ; change to date you want to test
'The file ' + $sFile + ' has not been accessed in over ' + $TimeDiff + ' days.' ?
'The file ' + $sFile + ' Last Accessed: ' + $LADate + Right(fnGetFileProp($sFile,DateLastAccessed),-9) ?
EndIf
Function fnGetFileProp($sFile,$sProp)
Dim $objFSO, $objFile, $nul
$objFSO = CreateObject("Scripting.FileSystemObject")
If Not VarType($objFSO)=9 Exit 1 EndIf
$objFile = $objFSO.GetFile($sFile)
If Not VarType($objFile)=9 Exit 2 EndIf
$nul=Execute("$$fnGetFileProp = $$objFile."+$sProp)
If VarType($fnGetFileProp)=0 Exit 87 EndIf
EndFunction
function DateCalc($date1, $DateOrMod, optional $SingleDigit)
dim $_intDate1, $_intYear1, $_intMonth1, $_intDay1
dim $_intDate2, $_intYear2, $_intMonth2, $_intDay2
$date1 = split($date1,'/')
if ubound($date1) <> 2
exit 1
endif
$_intYear1 = val($date1[0])
$_intMonth1 = val($date1[1])
$_intDay1 = val($date1[2])
if $_intMonth1 < 3
$_intMonth1 = $_intMonth1 + 12
$_intYear1 = $_intYear1 - 1
endif
$_intDate1 = $_intDay1 + ( 153 * $_intMonth1 - 457 ) / 5 + 365 * $_intYear1 +
$_intYear1 / 4 - $_intYear1 / 100 + $_intYear1 / 400 - 306
select
case vartype($DateOrMod) = 3
$_intDate2 = $_intDate1 + $DateOrMod
if instr($_intDate2,'-') $_intDate2 = val(substr($_intDate2,2,len($_intDate2)-1)) endif
$_intYear2 = ( 100 * ( ( ( 100*($_intDate2+306)-25)/3652425)
- ( ((100*($_intDate2+306)-25)/3652425)/4)
) + (100*($_intDate2+306)-25)
) / 36525
$_intMonth2 = ( 5 * ( ( ( 100*($_intDate2+306)-25)/3652425)
- ( ((100*($_intDate2+306)-25)/3652425)/4)
+ ($_intDate2+306) - 365 * $_intYear2 - $_intYear2 / 4
) + 456
) / 153
$_intDay2 = ( ( ( 100*($_intDate2+306)-25)/3652425)
- ( ((100*($_intDate2+306)-25)/3652425)/4)
+ ($_intDate2+306) - 365 * $_intYear2 - $_intYear2 / 4
) - ( 153 * $_intMonth2 - 457
) / 5
if $_intMonth2 > 12 $_intYear2 = $_intYear2 + 1 $_intMonth2 = $_intMonth2 - 12 endif
if not $SingleDigit
if len($_intYear2 ) < 4
$_ = execute("for $i=1 to 4-len($$_intYear2) $$_intYear2 = '0' + $$_intYear2 next")
endif
$_intMonth2 = right("0" + $_intMonth2,2)
$_intDay2 = right("0" + $_intDay2,2)
endif
$DateCalc = '$_intYear2/$_intMonth2/$_intDay2'
case vartype($DateOrMod) = 8
$DateOrMod = split($DateOrMod,'/')
if ubound($DateOrMod) <> 2
exit 1
endif
$_intYear2 = val($DateOrMod[0])
$_intMonth2 = val($DateOrMod[1])
$_intDay2 = val($DateOrMod[2])
if $_intMonth2 < 3
$_intMonth2 = $_intMonth2 + 12
$_intYear2 = $_intYear2 - 1
endif
$_intDate2 = $_intDay2 + ( 153 * $_intMonth2 - 457 ) / 5 + 365 * $_intYear2 +
$_intYear2 / 4 - $_intYear2 / 100 + $_intYear2 / 400 - 306
$DateCalc = $_intDate1 - $_intDate2
;comment the next line if you wish to return negative results also !!!
if instr($DateCalc,'-') $DateCalc = val(substr($DateCalc,2,len($DateCalc)-1)) endif
case 1
exit 1
endselect
endfunction
|
|
Top
|
|
|
|
#125781 - 2004-08-30 12:49 PM
Re: Get the date a file was last accessed
|
Cybex
Getting the hang of it
   
Registered: 2004-07-21
Posts: 81
Loc: Brandon, FL.
|
TRUE that, for sorting. I just realized I do use that date format for my log files. I tried to wrap your code into an app to run against remote computers listed in an ini file and look for apps listed in the same ini file. But I think the way you scripted your originally will not work against remote computers. Please take a look at my poorly written code and see if this is the case or just reconfirm I don't have a clue. P.S. Sorry, I killed EXPLICIT for testing.
Break On Dim $SO, $inifile $SO=SetOption('Explicit','OFF')
; Absolute path for the INI file $inifile = "K:\Kix Scripts\Kix\test.ini"
ENUMCOMPUTERS($inifile, "Computers")
Function CHECKAGE($CompName, $AppName) Dim $HKLMAppPaths,$sFile,$LADate,$TimeDiff $HKLMAppPaths=$CompName +'\HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths' $sFile=Trim(ReadValue($HKLMAppPaths + '\' + $AppName,'')) $LADate=Split(Trim(Join(Split(fnGetFileProp($sFile,DateLastAccessed),""),"",1)),"/") $LADate=$LADate[2]+"/"+Right("0"+$LADate[0],2)+"/"+Right("0"+$LADate[1],2) $TimeDiff=DateCalc(@DATE,$LADate) If $TimeDiff => 2 ; change to date you want to test MessageBox('The file ' + $sFile + ' has not been accessed in over ' + $TimeDiff + ' days.','Test',,) MessageBox('The file ' + $sFile + ' Last Accessed: ' + $LADate + Right(fnGetFileProp($sFile,DateLastAccessed),-10), 'Test',,) EndIf EndFunction Function fnGetFileProp($sFile,$sProp) Dim $objFSO, $objFile, $nul $objFSO = CreateObject("Scripting.FileSystemObject") If NOT VarType($objFSO)=9 Exit 1 EndIf $objFile = $objFSO.GetFile($sFile) If NOT VarType($objFile)=9 Exit 2 EndIf $nul=Execute("$$fnGetFileProp = $$objFile."+$sProp) If VarType($fnGetFileProp)=0 Exit 87 EndIf EndFunction Function DateCalc($date1, $DateOrMod, optional $SingleDigit) Dim $_intDate1, $_intYear1, $_intMonth1, $_intDay1 Dim $_intDate2, $_intYear2, $_intMonth2, $_intDay2 $date1 = Split($date1,'/') If Ubound($date1) <> 2 Exit 1 EndIf $_intYear1 = Val($date1[0]) $_intMonth1 = Val($date1[1]) $_intDay1 = Val($date1[2]) If $_intMonth1 < 3 $_intMonth1 = $_intMonth1 + 12 $_intYear1 = $_intYear1 - 1 EndIf $_intDate1 = $_intDay1 + ( 153 * $_intMonth1 - 457 ) / 5 + 365 * $_intYear1 + $_intYear1 / 4 - $_intYear1 / 100 + $_intYear1 / 400 - 306 Select Case VarType($DateOrMod) = 3 $_intDate2 = $_intDate1 + $DateOrMod If InStr($_intDate2,'-') $_intDate2 = Val(SubStr($_intDate2,2,Len($_intDate2)-1)) EndIf $_intYear2 = ( 100 * ( ( ( 100*($_intDate2+306)-25)/3652425) - ( ((100*($_intDate2+306)-25)/3652425)/4) ) + (100*($_intDate2+306)-25) ) / 36525 $_intMonth2 = ( 5 * ( ( ( 100*($_intDate2+306)-25)/3652425) - ( ((100*($_intDate2+306)-25)/3652425)/4) + ($_intDate2+306) - 365 * $_intYear2 - $_intYear2 / 4 ) + 456 ) / 153 $_intDay2 = ( ( ( 100*($_intDate2+306)-25)/3652425) - ( ((100*($_intDate2+306)-25)/3652425)/4) + ($_intDate2+306) - 365 * $_intYear2 - $_intYear2 / 4 ) - ( 153 * $_intMonth2 - 457 ) / 5 If $_intMonth2 > 12 $_intYear2 = $_intYear2 + 1 $_intMonth2 = $_intMonth2 - 12 EndIf If NOT $SingleDigit If Len($_intYear2 ) < 4 $_ = Execute("for $i=1 to 4-len($$_intYear2) $$_intYear2 = '0' + $$_intYear2 next") EndIf $_intMonth2 = Right("0" + $_intMonth2,2) $_intDay2 = Right("0" + $_intDay2,2) EndIf $DateCalc = '$_intYear2/$_intMonth2/$_intDay2' Case VarType($DateOrMod) = 8 $DateOrMod = Split($DateOrMod,'/') If Ubound($DateOrMod) <> 2 Exit 1 EndIf $_intYear2 = Val($DateOrMod[0]) $_intMonth2 = Val($DateOrMod[1]) $_intDay2 = Val($DateOrMod[2]) If $_intMonth2 < 3 $_intMonth2 = $_intMonth2 + 12 $_intYear2 = $_intYear2 - 1 EndIf $_intDate2 = $_intDay2 + ( 153 * $_intMonth2 - 457 ) / 5 + 365 * $_intYear2 + $_intYear2 / 4 - $_intYear2 / 100 + $_intYear2 / 400 - 306 $DateCalc = $_intDate1 - $_intDate2 ;comment the next line if you wish to return negative results also !!! If InStr($DateCalc,'-') $DateCalc = Val(SubStr($DateCalc,2,Len($DateCalc)-1)) EndIf Case 1 Exit 1 EndSelect EndFunction
Function ENUMCOMPUTERS($fl,$sectionentry) Dim $CompKeys,$CompName $CompKeys=Split(ReadProfileString($fl,$sectionentry,''),Chr(10)) For Each $CompName In $CompKeys If $CompName <>'' MessageBox($CompName, "Computer",,) ENUMAPPS($fl, "Apps", $CompName) EndIf EndFunction
Function ENUMAPPS($fl, $sectionentry, $CompName) Dim $AppKeys,$AppName $AppKeys=Split(ReadProfileString($fl,$sectionentry,''),Chr(10)) For Each $AppName In $AppKeys ; MessageBox("hi","hi",,) If $AppName <>'' MessageBox($AppName, "Computer and App",,) CHECKAGE($CompName, $AppName) EndIf EndFunction
_________________________
Common sense isn't so common.
|
|
Top
|
|
|
|
#125782 - 2004-08-30 02:27 PM
Re: Get the date a file was last accessed
|
Anonymous
Anonymous
Unregistered
|
The test.ini looks normal...
[Computers] bmw=0 tigger=0
[Apps] powerpoint.exe=0 dialer.exe=0 MPIO manager 2.exe=0
There has to be a better format for the ini file. I was thinking .. [Computers] comp1=bmw comp2=tigger
[Apps] app1=powerpoint.exe app2=dialer.exe app3=MPIO manager 2.exe
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Henriques)
and 2516 anonymous users online.
|
|
|