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 Version and Dir Mgmt

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

FileVerInfo Example for Recursive File Searches

Keywords:     FileVerInfo

;**************************************************************************
;FILEVER utility for recording the versions of specified filetypes into
;a text file. Written by Edward Tippelt  ert@pobox.com
;Uses the Winbatch SEARCHER extender, so only works in 32 bit environments
;Requires Winbatch 98 implementation of FileVerInfo command
;The text file produced by this program can be imported by MS Access or
;any other database and the results then sorted to suit your requirements.
;Version 3.41 dated 4 December 1998
;**************************************************************************
Sounds(0)
AddExtender("wsrch34I.dll")

;Define temporary files

if !DirExist("C:\Temp") then DirMake("C:\Temp")
tempfile1="C:\Temp\$ETL$TEMP$FILE$1.TXT"
tempfile2="C:\Temp\$ETL$TEMP$FILE$2.TXT"

:begin
FileVer32Format=`WWWDLGED,5.0`

FileVer32Caption=`File Version Utility V3.41 - 4 December 1998`
FileVer32X=50
FileVer32Y=83
FileVer32Width=292
FileVer32Height=146
FileVer32NumControls=8

FileVer3201=`16,24,96,DEFAULT,STATICTEXT,DEFAULT,"Starting Drive and Directory:"`
FileVer3202=`26,52,86,DEFAULT,STATICTEXT,DEFAULT,"File Extension to look for:"`
FileVer3203=`10,80,102,DEFAULT,STATICTEXT,DEFAULT,"File and path for search result:"`
FileVer3204=`126,24,148,DEFAULT,EDITBOX,Drive,"C:\"`
FileVer3205=`126,52,64,DEFAULT,EDITBOX,Extension,"*.DLL"`
FileVer3206=`126,80,148,DEFAULT,EDITBOX,outfile,"C:\TEMP\DLLVER.TXT"`
FileVer3207=`36,122,126,DEFAULT,PUSHBUTTON,DEFAULT,"OK",1`
FileVer3208=`184,122,64,DEFAULT,PUSHBUTTON,DEFAULT,"CANCEL",0`

ButtonPushed=Dialog("FileVer32")

;remove any existing outfile
;create attempt makes sure any existing file is not read-only and directory exists, etc
new = FileOpen(outfile, "WRITE")
FileClose(new)

;Check Starting Drive and Directory format
If StrLen(drive)<3
Message("Entry Error","The Starting Drive and Directory format is incorrect%@CRLF%%@CRLF%Press OK to re-enter this parameter")
goto begin
endif

;Check Starting Drive and Directory exist
If !Direxist(drive)
 Message("Entry Error","The Starting Drive and Directory cannot be found%@CRLF%%@CRLF%Press OK to re-enter this parameter")
 goto begin
endif

;Check Extension for correct format
If StrLen(Extension)<3 	   ;ie has to be at least *.c for example
 Message("Entry Error","The File Extension format is incorrect%@CRLF%%@CRLF%Press OK to re-enter this parameter")
 goto begin
endif

fh=FileOpen(tempfile1,"WRITE")

Edcount=0

   BoxOpen("Searching from %Drive%","")
   If StrSub(Drive,StrLen(Drive),1)!= "\" Then Drive=StrCat(Drive,"\")
   
   handle=srchInit(Drive,Extension,"",0,16)

:start
        Edfile=srchNext(handle)
        ;boxtext(edfile)
        if Edfile=="" then goto finish  
        Edcount=Edcount+1
        pos=StrIndex(Edfile,"\",0,@backscan)+1
        filename=StrSub(Edfile,pos,-1)
        dd=FileYmdHms(Edfile)   
        ss=FileSize(Edfile)
       ;ErrorMode(@OFF)
:loop
        pv=FileVerInfo(Edfile,"","ProductVersion")
        if pv=="" then pv="None"
:nextp  fv=FileVerInfo(Edfile,"","FileVersion")
        if fv=="" then fv="None"
       ;ErrorMode(@Cancel)          
        ee=strfix(Edcount," ",6)   
        dd=strfix(dd," ",20)   
        ss=strfix(ss," ",10)
        pv=strfix(pv," ",20)
        fv=strfix(fv," ",20)
        filename=strfix(filename," ",20)   
;        line=strcat(ee,filename,pv,fv,dd,ss,Edfile)   
        line=strcat(filename,pv,fv,dd,ss,Edfile)   
        FileWrite(fh,line)
        BoxText(line)
        goto start
:finish 
   srchFree(handle)

FileClose(fh)
;Now check to make sure there is something to sort

If Edcount==0
 BoxShut()
; Message("File Search complete","Nothing found matching entry parameters")
 ;cleanup
 if FileExist(tempfile2) then FileDelete(tempfile2)
 if FileExist(tempfile1) then FileDelete(tempfile1)
 Choice=AskYesNo("FILE SEARCH COMPLETE","Nothing found matching entry parameters%@CRLF%%@CRLF%Do you want to run again?")
 if Choice==@yes then goto begin
 EXIT
Endif 

Boxtitle("File Search complete")

Boxtext("Sorting Results - Please Wait")

old = FileOpen(tempfile1, "READ")
;Find the longest string in the file
longest=0
loopcount=0
while @TRUE             ; Loop till break do us end
        xetl = FileRead(old)
        If xetl == "*EOF*" Then Break
        loopcount=loopcount+1
        length=strlen(xetl)
        if length>longest then longest=length
endwhile
FileClose(old)

If loopcount==0 ;Nothing was found
 BoxShut()
; Message("File Search complete","Nothing found matching entry parameters")
 ;cleanup
 if FileExist(tempfile2) then FileDelete(tempfile2)
 if FileExist(tempfile1) then FileDelete(tempfile1)
 Choice=AskYesNo("FILE SEARCH COMPLETE","Nothing found matching entry parameters%@CRLF%%@CRLF%Do you want to run again?")
 if Choice==@yes then goto begin
 EXIT
Endif 

;Now create a sort file with fixed length records
;by adding spaces to the end of shorter lines

;A check for disk space could go here
;Bytesrequired = loopcount*longest

;create sort file
old = FileOpen(tempfile1, "READ")
new = FileOpen(tempfile2, "WRITE")
while @TRUE             ; Loop till break do us end
        xetl = FileRead(old)
        If xetl == "*EOF*" Then Break
        xetl=strfix(xetl," ",longest)   
        FileWrite(new, xetl)
endwhile
FileClose(new)
FileClose(old)

;Now sort the entries in the file
RecSize=longest+2   ;as there is a CRLF at the end of each line
NameOffset=0        ;we are sorting on the filename, which is the first field
NameSize=20         ;the parameter: filename  is fixed at 20 chars in the search routine

dbsize=FileSize(tempfile2)
db=BinaryAlloc(dbsize)
BinaryRead(db,tempfile2)
BinarySort(db,RecSize,NameOffset,NameSize,@STRING|@ASCENDING)

BinaryWrite(db,tempfile2)
BinaryFree(db)

;Finally, get rid of trailing spaces in the temp file
;and write to the filename chosen by the user

old = FileOpen(tempfile2, "READ")
new = FileOpen(outfile, "WRITE")
while @TRUE             ; Loop till break do us end
        xetl = FileRead(old)
        If xetl == "*EOF*" Then Break
        xetl=strtrim(xetl)   
        FileWrite(new, xetl)
endwhile
FileClose(new)
FileClose(old)

;cleanup temp files
FileDelete(tempfile2)
FileDelete(tempfile1)

;Message("Longest Line = %longest%","Space required = %Bytesrequired% %@crlf% Number of files = %loopcount%")

BoxShut()
;Message("Sort complete","Result in %outfile%")
Choice=AskYesNo("SORT COMPLETE","Result in:%@CRLF%%outfile%%@CRLF%%@CRLF%Do you want to run again?")
if Choice==@yes then goto begin

Exit
:cancel
display(2,"File Version Utility","Program Cancelled")
Exit



Article ID:   W13779
Filename:   FileVerInfo with Searcher for Recursion.txt
File Created: 2001:03:01:12:46:48
Last Updated: 2001:03:01:12:46:48