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.

Directory Index


AddExtender("wsrch34i.dll")

WorkingDir = AskDirectory("Which Directory Would You Like To Scan", "", "", "",0) 
dirchange(WorkingDir)

;give us just the path of the exe
exeDir = FilePath (IntControl (1004, 0, 0, 0, 0)) 
OutputSiteHTML = StrCat(exeDir,"Index.htm")
OutputFileHandle = FileOpen(OutputSiteHTML, "WRITE")

gosub WriteHTMLHeader

;Status Box
BoxColor(1,"255,0,0",2)   ;sets the background color
;BoxTextFont(1, "Terminal", 80, 0, 1)
BoxTextColor(1,"255,255,0")
BoxTextFont(1, "Times Roman", 45, 0, 16)
BoxOpen("Start","Reading Directory File...")
BoxDataTag(1,"tiptop")

;------------------------------------------------------------------------------------------------
;Loop through directories
firstrun = 1
handDirectorySearch=srchInit(WorkingDir,"","","",16|32)
while @TRUE             ; Loop till break do us end
	  DirectoryName=srchNext(handDirectorySearch)
	  if DirectoryName=="" then break

	  if firstrun == 1 then
	  	  firstrun = 0
		  FileWrite(OutputFileHandle,'<H1> Directories </H1>')
		  HTMLMsg = StrCat('<a href="#',WorkingDir,'"><B>',WorkingDir,'</B></a><BR>')
		  FileWrite(OutputFileHandle,HTMLMsg)
		  FileWrite(OutputFileHandle,'<table border="5" CELLSPACING=1 CELLPADDING=3 WIDTH="100%%">')
		  FileWrite(OutputFileHandle,'<colgroup span="2">')
		  FileWrite(OutputFileHandle,'<col width="20%%">')
		  FileWrite(OutputFileHandle,'<col width="80%%">')
		  FileWrite(OutputFileHandle,'</colgroup>')
		  FileWrite(OutputFileHandle,'<tr align="left" style="color: green">')
		  FileWrite(OutputFileHandle,'<th><B>Directory Size</B></th>')
		  FileWrite(OutputFileHandle,'<th><B>DirectoryName</B></th>')
		  FileWrite(OutputFileHandle,'</tr>')
	  else
		  BoxDataClear(1,"tiptop")
		  if StrSub(DirectoryName,StrLen(DirectoryName),-1) == "\" then
			  Msg = StrCat("Processing Directories ",@CRLF,DirectoryName) 
			  BoxText(Msg)
			  Size = DirSize (DirectoryName, 0)

			  ;Format the byte's returned
			  t1 = ""
			  PosCount = 0
			  for xloop = StrLen(Size) to 1 by -1
			  		t1 = StrCat(StrSub(Size,xloop,1),t1)
					PosCount = PosCount + 1
					;put a ',' every 3 positions, but don't put one at the 
					;front of the string if there is no more data
					if PosCount == 3 && xloop <> 1 then
						PosCount = 0

						t1 = StrCat(',',t1)
					end if
			  next xloop
			  FormatSize = t1

			  FileWrite(OutputFileHandle,'<TR>')
			  if Size > 9999999 then
				  HTMLMsg = StrCat('<td align="right"><font color=red>',FormatSize,'</TD>')
			  else
			  	  if Size > 99999 then
					  HTMLMsg = StrCat('<td align="right"><font color=blue>',FormatSize,'</TD>')
				  else
					  HTMLMsg = StrCat('<td align="right"><font color=green>',FormatSize,'</TD>')
				  end if
			  end if
			  FileWrite(OutputFileHandle,HTMLMsg)

			  HTMLMsg = StrCat('<TD><a href="#',DirectoryName,'"><B>',DirectoryName,'</B></a><BR></TD>')
			  FileWrite(OutputFileHandle,HTMLMsg)
			  FileWrite(OutputFileHandle,'</TR>')
		  end if
	  end if
endwhile
;if first run = 0, then we need to write out the end table tag
if firstrun == 0 then
	  FileWrite(OutputFileHandle,'</TABLE>')
end if
;------------------------------------------------------------------------------------------------
;Loop through files

svDirectory = ""
WriteEndTableTag = 0
handFileSearch=srchInit(WorkingDir,"*.*","","",8|16)
while @TRUE             ; Loop till break do us end
	  FileName=srchNext(handFileSearch)
	  size = FileSize(FileName)

	  if FileName=="" then break

	  BoxDataClear(1,"tiptop")
	  Msg = StrCat("Processing File ",@CRLF,FileName) 
	  BoxText(Msg)

	  t1 = StrIndex(FileName,"\",StrLen(FileName),@BACKSCAN)
	  File = StrSub(FileName,t1+1,-1)  ;Just get the filename
	  Directory = StrSub(FileName,1,t1-1)  ;Just get the filename

	  if Directory <> svDirectory then
	  	  svDirectory = Directory
		  if WriteEndTableTag == 1 then FileWrite(OutputFileHandle,'</TABLE>')

		  HTMLMsg = StrCat('<HR><a name="',Directory,'\"</a><a href="',Directory,'"><B><H1>',Directory,'</B></H1></a><BR>')
		  FileWrite(OutputFileHandle,HTMLMsg)
	  	
		  FileWrite(OutputFileHandle,'<table border="5" CELLSPACING=1 CELLPADDING=3 WIDTH="100%%">')
		  FileWrite(OutputFileHandle,'<colgroup span="3">')
		  FileWrite(OutputFileHandle,'<col width="20%%">')
		  FileWrite(OutputFileHandle,'<col width="70%%">')
		  FileWrite(OutputFileHandle,'<col width="10%%">')
		  FileWrite(OutputFileHandle,'</colgroup>')
		  FileWrite(OutputFileHandle,'<tr align="left" style="color: green">')
		  FileWrite(OutputFileHandle,'<th><B>File Size</B></th>')
		  FileWrite(OutputFileHandle,'<th><B>File Name</B></th>')
		  FileWrite(OutputFileHandle,'<th><B>Modified Date</B></th>')
		  FileWrite(OutputFileHandle,'</tr>')

		  WriteEndTableTag = 1

	  end if

	  ;Format the byte's returned
	  Size = FileSize (FileName, 0)
	  t1 = ""
	  PosCount = 0
	  for xloop = StrLen(Size) to 1 by -1
	  		t1 = StrCat(StrSub(Size,xloop,1),t1)
			PosCount = PosCount + 1
			if PosCount == 3 && xloop <> 1 then
				PosCount = 0

				t1 = StrCat(',',t1)
			end if
	  next xloop
	  FormatSize = t1
									  
	  FileWrite(OutputFileHandle,'<TR>')
	  if Size > 9999999 then
		  HTMLMsg = StrCat('<td align="right"><font color=red>',FormatSize,'</TD>')
	  else
	  	  if Size > 99999 then
			  HTMLMsg = StrCat('<td align="right"><font color=blue>',FormatSize,'</TD>')
		  else
			  HTMLMsg = StrCat('<td align="right"><font color=green>',FormatSize,'</TD>')
		  end if
	  end if
	  FileWrite(OutputFileHandle,HTMLMsg)

	  HTMLMsg = StrCat('<TD><a href="',FileName,'">',File,'</B></a></TD>')
	  FileWrite(OutputFileHandle,HTMLMsg)

	  ;need to check this because there weird files like 'advanced_image_search[1].' in the explorer temporary
	  ;directories which are invalid!
	  if FileExist(FileName) then
		  t1 = FileYmdHms(filename)
	 	  t2 = StrCat(ItemExtract(1,t1,":"),"/",ItemExtract(2,t1,":"),"/",ItemExtract(3,t1,":"))
	  else
	  	  t2 = ""
	  end if
	  HTMLMsg = StrCat('<TD>',t2,'</TD>')
	  FileWrite(OutputFileHandle,HTMLMsg)

	  FileWrite(OutputFileHandle,'</TR>')

endwhile

if WriteEndTableTag == 1 then FileWrite(OutputFileHandle,'</TABLE>') ;write final table tag

gosub WriteHTMLFooter
srchFree(handFileSearch)
FileClose(OutputFileHandle)

;Open output
Run (OutputSiteHTML, "")

exit
;---------------------------------------------------------------------------------------------------------------------------------
:WriteHTMLHeader

	FileWrite(OutputFileHandle,"<HTML>")
	FileWrite(OutputFileHandle,"<HEAD>")
	FileWrite(OutputFileHandle,"<TITLE>Directories</TITLE>")
	FileWrite(OutputFileHandle,"</HEAD>")
	FileWrite(OutputFileHandle,'<BODY>')

return
;---------------------------------------------------------------------------------------------------------------------------------
:WriteHTMLFooter

	FileWrite(OutputFileHandle,"</body>")
	FileWrite(OutputFileHandle,"</html>")

return

Article ID:   W16214
File Created: 2004:08:25:10:48:48
Last Updated: 2004:08:25:10:48:48