WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

File And Folder Extender

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Disk Scan Sample

 Keywords: Searcher Files Directory File and Folder Extender Details Properties fafOpen fafGetInfo fafFind Attribute Path

Example for simple disk scan using the "File and Folder Extender".
;==========================================================================================================================================
; Example for simple disk scan
; using the "File and Folder Extender".
;
; Detlev Dalitz.20090814.
;==========================================================================================================================================


;------------------------------------------------------------------------------------------------------------------------------------------
; User tweak section
;------------------------------------------------------------------------------------------------------------------------------------------
;
; Define folder from where to start.
strFolderStart = "D:\"
;
; Define folder-file-mask for the search process.
strFFMask = "*.*"
;
; Define name of the CSV output file.
; This file will be created in the Subfolder "DiskScan" within the user's temp folder.
strFileOut = "DiskScan.csv.txt"
;
; Define usage of box display.
blnDisplayStatus = @TRUE
;
; Define box display progress speed. Small step width will increase runtime.
intMsgStep = 100
;
;------------------------------------------------------------------------------------------------------------------------------------------


#DefineFunction udfFormatStringOR (intValue)
strOR = ""
For intI = 0 To 16
   intBit = intValue & (1 << intI)
   If intBit Then strOR = "|" : intBit : strOR
   intValue = intValue - intBit
   If !intValue Then Break
Next
Return StrSub (strOR, 2, -1)
#EndFunction


AddExtender ("wwfaf44i.dll") ; File and Folder Finder Extender.
;intFFInfo0 = fafGetInfo (0) ; Extender version number.
;intFFInfo1 = fafGetInfo (1) ; Number of functions implemented by the extender.
;intFFInfo2 = fafGetInfo (2) ; Number of manifest constants implemented by the extender.
;intFFInfo3 = fafGetInfo (3) ; Returns one (1) if 64-bit Windows file redirection is enabled and zero (0) if it is not. Note: This request reports the current state of the WinBatch process and does not reflect the current fafOpen function's flags file redirection parameter value
;intFFInfo4 = fafGetInfo (4) ;  Count of currently active search contexts.
;intFFInfo5 = fafGetInfo (1234) ; Text associated with the extender error number or an empty string (""), if the value is not a valid extender error number.

; Initialize flags for readability
intFFDefault = 0      ; Use extender defaults, same as not specifying a value for the parameter.
intFFHidden = 1       ; * Include 'hidden' file and folders in search results.
intFFSystem = 2       ; * Include 'system' files and folders in the search results.
intFFFolders = 4      ; Inspect subfolders names.
intFFFolderMatch = 8  ; Only return folder items that match file-mask. (implies option 4)
intFFRecurse = 16     ; Search the sub-directories of root-path.
intFFNoPathInfo = 32  ; Do not return path information to files or folders found.
intFFNoRedirect = 64  ; ** Do not turn off file redirection. x64 versions of Windows client and server only.
; * Also affects the sub-directories searched when flag 8 is also set.
; ** By default file redirection is turned off for the duration of extender function calls
; and has no effect on any other WinBatch functions or operators.
; When WinBatch IntControl 92 is used to turn off file redirection, this flag is ignored
; and does not turn file redirection back on for extender function calls.


strFolderTemp = Environment ("TEMP") : "\DiskScan\"
Terminate (!DirMake (strFolderTemp), "Terminated.", "Cannot access temporary folder:" : @LF : strFolderTemp)
strFileOut = strFolderTemp : strFileOut

strMsgTitle = "Simple disk scan"
strMsgText = "Running ..."
BoxOpen (strMsgTitle, strMsgText)
WinPlaceSet (@NORMAL, "", "400 200 900 700")

IntControl (40, 1, 0, 0, 0) ; p1=1, allow other open operations for read access. Not necessary, can be umcommented.
hdlFW = FileOpen (strFileOut, "WRITE")

hdlFF = fafOpen (strFolderStart, strFFMask, intFFRecurse | intFFFolders | intFFSystem | intFFHidden)

intCount = 0
While @TRUE
   strPath = fafFind (hdlFF)
   If strPath == "" Then Break

   Switch DirExist (strPath)
   Case @FALSE
      intAttr = FileAttrGetEx (strPath)
      strType = "File"
      Break
   Case @TRUE
      intAttr = DirAttrGetEx (strPath)
      strType = "Folder"
      Break
   EndSwitch
   strAttr = udfFormatStringOR (intAttr)

   intCount = intCount + 1

   If blnDisplayStatus
      If 1 == (intCount mod intMsgStep)
         strAttr = intAttr : StrSub (" = " : strAttr, 1, -1 * !!StriCmp (strAttr, intAttr))
         strMsgText = "Count: " : intCount : @LF : "Type: " : strType : @LF : "Attribute: " : strAttr : @LF : "Path:" : @LF : StrReplace (strPath, "\", "\" : @LF)
         BoxText (strMsgText)
      EndIf
   EndIf

   strOut = '"' : strPath : '"' : ',"' : strType : '","' : strAttr : '"'
   FileWrite (hdlFW, strOut)

EndWhile

If fafClose (hdlFF) Then Drop (hdlFF)
hdlFW = FileClose (hdlFW)
BoxShut ()

Run (strFileOut, "")

Exit

Article ID:   W17570
Filename:   Disk Scan Sample.txt
File Created: 2009:08:14:11:24:14
Last Updated: 2009:08:14:11:24:14