Here is some code I was working on to create a Directory View - please use as much as you want, and adapt it likewise, but I do request some sort of small credit (You don't have to, but it would be nice) and If you use the code, do tell me, as I am interested in how it could be used. It could be set to read a cirtain area only and get a level selector, there are many possiblities.
Anyway, do tell me what you think, I know it's slow, but I can't see any way of fixing that.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Directory View - Made By Lattyware
;;; //www.lattyware.com\\
;;; Note this is not a gadget, just a function (or two).
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; CreateDirectoryView(group,directory,x,y,width,height,viewfiles)
;;;
;;; Paramaters:
;;; group - A group gadget handle.
;;; directory - The directory to dig down from
;;; x,y,width,height - shape of the gadget.
;;; viewfiles - True to view files and folders, False for just folders.
;;;
;;; Description:
;;; Creates a directory browser.
;;;
;;; Example:
;;;
;;; window=CreateWindow("Directory Browser",0,0,800,600,0,1)
;;; CreateDirectoryView(window,"C:\",50,50,650,450,True)
;;; While Not id=$803
;;; id=WaitEvent()
;;; Wend
;;; End
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Below are the two functions to add if you wish to use.
Function CreateDirectoryView(window,drive$,startx,starty,width,height,viewfiles)
main=CreateTreeView(startx,starty,width,height,window)
root1=TreeViewRoot(main)
folder=AddTreeViewNode(drive$,root1)
AddFolderContents(drive$,file$,folder,viewfiles)
End Function
Function AddFolderContents(drive$,file$,folder,viewfiles)
dir=ReadDir(drive$+"\"+file$)
While MoreFiles(dir)
file2$=NextFile(dir)
If file2$ <> "." Then
If file2$ <> ".." Then
If FileType(drive$+"\"+file$+"\"+file2$) = 2 Then
folder2=AddTreeViewNode(file2$,folder)
drive2$=drive$+"\"+file$
AddFolderContents(drive2$,file2$,folder2,viewfiles)
Else
If viewfiles=True Then folder2=AddTreeViewNode(file2$,folder)
EndIf
EndIf
EndIf
Wend
End Function
|