;----------------------------------------------------------------------------------------------------
; udfCreateLogFileFooter (ArrBay) ; 2002:07:17:17:05:27
; udfCreateLogFileHeader (ArrBay) ; 2002:07:17:17:05:27
; udfHeaderScale (len, delimiter) ; 2002:07:17:17:05:27
; udfAddCommas (numstring) ; 2002:07:17:17:05:27
; udfProcessFile (ArrBay, sFileName) ; 2002:07:17:17:05:27
; udfProcessFolderFiles (ArrBay) ; 2002:07:17:17:05:27
; udfProcessFolderTree (ArrBay, sFolder) ; 2002:07:17:17:05:27
;----------------------------------------------------------------------------------------------------
;------------------------------------------------------------------------------------------------------------------------------------------
; Build a report of files on the NetWare server,
; which were last modified more than x days before now.
; Detlev Dalitz.20020717
;------------------------------------------------------------------------------------------------------------------------------------------
;==========================================================================================================================================
;--- user configurable area begin ---
sLogFileName = "D:\TEMP\LOG.TXT" ; Specify a filename for the log file.
sNwServerFolder = "W:\" ; UNC name allowed \\SERVER\SHARE\FOLDER\...
sFolderMask = "*oo*" ; Specify a filter for foldernames.
sFileMask = "*.exe" ; Specify a filter for filenames.
iDiffDays = 90 ; How old, last modified before x days.
bSafeMode = 0 ; Activate safer error checking on file access
iDisplayStep = 25 ; Display search activity on every each x steps.
bVerboseMode = 0 ; More information about old files
;--- user configurable area end ---
;==========================================================================================================================================
AddExtender('WWNWX34I.DLL')
Gosub DefineUDF
IntControl(5,1,0,0,0) ; Allow system and hidden files to be counted.
sCurrentFolder = DirGet() ; Save for later restore.
sProcessStart = TimeYmdHms()
sNwServerFolder = StrCat(sNwServerFolder,StrSub("\",(StrSub(sNwServerFolder,StrLen(sNwServerFolder),1)<>"\"),1)) ; Add Backslash for sure.
If (sFolderMask=="") Then sFolderMask="*"
ArrBay = ArrDimension(13)
ArrBay[0] = sLogFileName
ArrBay[1] = 0 ; hFW
ArrBay[2] = 0 ; iFileCountOld
ArrBay[3] = 0 ; iFileSum
ArrBay[4] = 0 ; iFileCount
ArrBay[5] = sFolderMask
ArrBay[6] = sFileMask
ArrBay[7] = iDiffDays
ArrBay[8] = bSafeMode
ArrBay[9] = iDisplayStep
ArrBay[10] = bVerboseMode
ArrBay[11] = sProcessStart
ArrBay[12] = "" ; sProcessStop
udfCreateLogFileHeader (ArrBay)
BoxOpen(StrCat("Filesearch started ",sProcessStart," days diff.=",iDiffDays), "Searching")
udfProcessFolderTree(ArrBay,sNwServerFolder)
BoxShut()
udfCreateLogFileFooter (ArrBay)
ProcessStop = TimeYmdHms()
Message("Filesearch completed",StrCat("start",@tab,sProcessStart,@crlf,"stop",@tab,ProcessStop))
IntControl(5,0,0,0,0) ; protect System & Hidden files and directories
DirChange(sCurrentFolder) ; back to start folder
; take a look into the logfile
RunZoom(StrCat(DirHome(),"browser.exe"),sLogFileName)
TimeDelay(1)
SendKey("^t!tf!g8~")
Exit
:cancel
IntControl(72,2,0,0,0) ; Sets Cancel handler. Gosub the label :CANCEL
; Do error handling if necessary.
Return
;==========================================================================================================================================
:DefineUDF ; User Defined Functions and User Defined SubRoutines
;==========================================================================================================================================
;
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfCreateLogFileFooter (ArrBay)
hFW = ArrBay[1]
iFileSum = ArrBay[3]
iFileCountOld = ArrBay[2]
sOut = StrCat(StrFixLeft(udfAddCommas(iFileSum),"",15)," ",udfAddCommas(iFileCountOld)," files summed")
FileWrite(hFW,"")
FileWrite(hFW,sOut)
FileWrite(hFW,"")
FileWrite(hFW,TimeYmdHms())
FileClose(hFW)
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfCreateLogFileHeader (ArrBay)
sLogFileName = ArrBay[0]
sFolderMask = ArrBay[5]
sFileMask = ArrBay[6]
iDiffDays = ArrBay[7]
bSafeMode = ArrBay[8]
sProcessStart = ArrBay[11]
hFW = FileOpen(sLogFileName,"WRITE")
FileWrite(hFW,udfHeaderScale(300,@crlf))
sOut=StrCat('LogFileName = "',sLogFileName,'"')
FileWrite(hFW,sOut)
sOut=StrCat('FolderMask = "',sFolderMask,'"')
FileWrite(hFW,sOut)
sOut=StrCat('FileMask = "',sFileMask,'"')
FileWrite(hFW,sOut)
sOut=StrCat('Day Difference = ',iDiffDays)
FileWrite(hFW,sOut)
FileWrite(hFW,"")
FileWrite(hFW,sProcessStart)
FileWrite(hFW,"")
sOut=""
sOut=StrCat(sOut ,StrFixLeft("Size KB","",15))
sOut=StrCat(sOut," ",StrFix("Accessed","",15))
sOut=StrCat(sOut," ",StrFix("Creator" ,"",15))
sOut=StrCat(sOut," ",StrFix("Created" ,"",21))
sOut=StrCat(sOut," ",StrFix("Modifier","",15))
sOut=StrCat(sOut," ",StrFix("Modified","",21))
sOut=StrCat(sOut," ",StrFix("Archiver","",15))
sOut=StrCat(sOut," ",StrFix("Archived","",21))
If bSafeMode Then sOut = StrCat(sOut," ",StrFixLeft("ErrNr","",5))
sOut=StrCat(sOut," ","Filename")
FileWrite(hFW,sOut)
ArrBay[1] = hFW
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfHeaderScale (len, delimiter)
p = 0
n = len
While @true
n = n/10
If (n==0) Then Break
p = p+1
EndWhile
sOut = ""
While (p>0)
sStr = ""
hmax = 1+(len/(10**p))
filler = StrFill("_",(10**p)-1)
For h=1 To hmax
sStr = StrCat(sStr,filler,h mod 10)
Next
sStr = StrSub(sStr,1,len)
sOut = StrCat(sOut,sStr,delimiter)
p = p-1
EndWhile
sStr = StrFill("1234567890",len)
sOut = StrCat(sOut,sStr,delimiter)
Return (sOut)
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfAddCommas (numstring)
intpart=ItemExtract(1,numstring, ".")
fractpart=ItemExtract(2,numstring,".")
groups=((StrLen(intpart)-1)/3)+1
answer=""
For y=1 To groups
If y==1
ptr=((StrLen(intpart)-1) mod 3)+1
answer=StrSub(intpart,1,ptr)
ptr=ptr+1
Else
answer=StrCat(answer,",",StrSub(intpart,ptr,3))
ptr=ptr+3
EndIf
Next
If (fractpart<>"") Then answer=StrCat(answer,".",fractpart)
Return (answer)
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfProcessFile (ArrBay, sFileName)
hFW = ArrBay[1]
iFileCountOld = ArrBay[2]
iFileSum = ArrBay[3]
iFileCount = ArrBay[4]
iDiffDays = ArrBay[7]
bSafeMode = ArrBay[8]
iDisplayStep = ArrBay[9]
bVerboseMode = ArrBay[10]
sProcessStart = ArrBay[11]
iFileCount = iFileCount+1
sFileName = FileFullname(sFileName)
If FileExist(sFileName)
If bSafeMode
LastErrorMode=ErrorMode(@off)
IntControl(72,2,0,0,0)
LastError()
accessed = nwGetFileInfo(sFileName,5,"","",0)
iResult = LastError()
ErrorMode(LastErrorMode)
; do error handling if necessary
LastErrorMode=ErrorMode(@off)
IntControl(72,2,0,0,0)
LastError()
modifier = nwGetFileInfo(sFileName,4,"","",0)
iResult = LastError()
ErrorMode(LastErrorMode)
; do error handling if necessary
LastErrorMode=ErrorMode(@off)
IntControl(72,2,0,0,0)
LastError()
modified = nwGetFileInfo(sFileName,3,"","",0)
iResult = LastError()
ErrorMode(LastErrorMode)
; do error handling if necessary
LastErrorMode=ErrorMode(@off)
IntControl(72,2,0,0,0)
LastError()
Creator = nwGetFileInfo(sFileName,2,"","",0)
iResult = LastError()
ErrorMode(LastErrorMode)
; do error handling if necessary
LastErrorMode=ErrorMode(@off)
IntControl(72,2,0,0,0)
LastError()
created = nwGetFileInfo(sFileName,1,"","",0)
iResult = LastError()
ErrorMode(LastErrorMode)
; do error handling if necessary
LastErrorMode=ErrorMode(@off)
IntControl(72,2,0,0,0)
LastError()
archived = nwGetFileInfo(sFileName,6,"","",0)
iResult = LastError()
ErrorMode(LastErrorMode)
; do error handling if necessary
LastErrorMode=ErrorMode(@off)
IntControl(72,2,0,0,0)
LastError()
archiver = nwGetFileInfo(sFileName,7,"","",0)
iResult = LastError()
ErrorMode(LastErrorMode)
; do error handling if necessary
Else
;accessed = FileTimeGetEx(sFileName, 3) ; accessed
;modified = FileTimeGetEx(sFileName, 2) ; modified
;created = FileTimeGetEx(sFileName, 1) ; created
archiver = nwGetFileInfo(sFileName,7,"","",0)
archived = nwGetFileInfo(sFileName,6,"","",0)
accessed = nwGetFileInfo(sFileName,5,"","",0)
modifier = nwGetFileInfo(sFileName,4,"","",0)
modified = nwGetFileInfo(sFileName,3,"","",0)
creator = nwGetFileInfo(sFileName,2,"","",0)
created = nwGetFileInfo(sFileName,1,"","",0)
EndIf
bIsOld = (TimeDiffDays(sProcessStart,modified) > iDiffDays)
Else
accessed = "unknown"
Creator = "unknown"
created = "unknown"
modifier = "unknown"
modified = "unknown"
archiver = "unknown"
archived = "unknown"
bIsOld = @true
EndIf
If !(iFileCount mod iDisplayStep)
dispcount = StrCat(StrFix("Count" ,"",15) ,@tab,udfAddCommas(iFileCount))
dispname = StrCat(StrFix("Filename" ,"",15) ,@tab,sFileName)
dispacc = StrCat(StrFix("Accessed" ,"",15) ,@tab,accessed)
dispcre = StrCat(StrFix("Created" ,"",15) ,@tab,created)
dispmod = StrCat(StrFix("Modified" ,"",15) ,@tab,modified)
disparch = StrCat(StrFix("Archived" ,"",15) ,@tab,archived)
dispold = StrCat(StrFix("File is old","",15) ,@tab,bIsOld)
sOut = StrCat(dispcount,@cr,dispname,@cr,dispacc,@cr,dispcre,@cr,dispmod,@cr,disparch,@cr,dispold)
If bVerboseMode
If bIsOld Then sFileNameOld = sFileName
Else sFileNameOld = ""
dispfnold = StrCat(StrFix("Filename old" ,"",15) ,@tab,sFileNameOld)
dispcreo = StrCat(StrFix("Creator" ,"",15) ,@tab,Creator)
dispmodo = StrCat(StrFix("Modifier" ,"",15) ,@tab,modifier)
disparcho = StrCat(StrFix("Archiver" ,"",15) ,@tab,archiver)
dispoldc = StrCat(StrFix("Count old" ,"",15) ,@tab,udfAddCommas(iFileCountOld))
dispsum = StrCat(StrFix("KB summed old" ,"",15) ,@tab,udfAddCommas(iFileSum))
dispperf = StrCat(StrFix("Files/sec" ,"",15) ,@tab,udfAddCommas(iFileCount/(1+TimeDiffSecs(TimeYmdHms(),sProcessStart))))
sOut = StrCat(sOut,@cr,@cr,dispoldc,@cr,dispfnold,@cr,dispcreo,@cr,dispmodo,@cr,disparcho,@cr,dispsum,@cr,@cr,dispperf)
EndIf
BoxText(sOut)
EndIf
If !bIsOld Then Goto labelreturn
iFileCountOld = iFileCountOld+1
iSizeKB = 0
iFileSize = FileSizeEx(sFileName)
If iFileSize Then iSizeKB = Int(1.0+(iFileSize/1024))
iFileSum = iFileSum + iSizeKB
sOut = ""
sOut = StrCat(sOut,StrFixLeft(udfAddCommas(iSizeKB) ,"",15))
sOut = StrCat(sOut," ",StrFix(StrSub(accessed,1,10),"",15))
sOut = StrCat(sOut," ",StrFix(Creator ,"",15))
sOut = StrCat(sOut," ",StrFix(created ,"",21))
sOut = StrCat(sOut," ",StrFix(modifier ,"",15))
sOut = StrCat(sOut," ",StrFix(modified ,"",21))
sOut = StrCat(sOut," ",StrFix(archiver ,"",15))
sOut = StrCat(sOut," ",StrFix(archived ,"",21))
If bSafeMode Then sOut = StrCat(sOut," ",StrFixLeft(iResult,"",5))
sOut = StrCat(sOut," ",sFileName)
FileWrite(hFW,sOut)
:labelreturn
ArrBay[2] = iFileCountOld
ArrBay[4] = iFileCount
ArrBay[3] = iFileSum
Return
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfProcessFolderFiles (ArrBay)
sFileMask = ArrBay[6]
sFileList = FileItemize(sFileMask)
iFileCount = ItemCount(sFileList,@tab)
For i=1 To iFileCount
sThisFile = ItemExtract(i,sFileList,@tab)
udfProcessFile(ArrBay,sThisFile)
Next
Return
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfProcessFolderTree (ArrBay, sFolder)
sFolderMask = ArrBay[5]
sCurrentFolder = DirGet()
DirChange(sFolder)
If StrLenwild(StrLower(sFolder),StrLower(sFolderMask),1) Then udfProcessFolderFiles(ArrBay)
sFolderList = DirItemize("*.*")
iFolderCount = ItemCount(sFolderList,@tab)
For i=1 To iFolderCount
sThisFolder = ItemExtract(i,sFolderList,@tab)
udfProcessFolderTree(ArrBay,sThisFolder) ; recursive
Next
DirChange(sCurrentFolder)
Return
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------
;
;==========================================================================================================================================
Return ; from gosub DefineUDF ; User Defined Functions and User Defined SubRoutines
;==========================================================================================================================================
|