Page 1 of 1
					
				Recursive folder tree+files with ExamineDirectory?
				Posted: Thu Jan 12, 2006 3:05 pm
				by Kaiser
				Hey 
I'm trying to make a program for my cousin (basically a small shell replacement) because her comp's really slow and wants some speed with games - so I thought a lighter shell would release CPU a little bit. Either way, I want to make her a start menu thing, so kay, that's good. Been tinkering with Droopy's Lib (which is awesome) I noticed it first gets the files in the subfolders and later the one in the root one (in Programs, I have a few items on there, and also folders). Now I wonder how would I get the root files FIRST then get the ones in the folders? either using or not using Droopy's lib?
Thanks in advance 

 
			 
			
					
				
				Posted: Thu Jan 12, 2006 11:10 pm
				by walker
				Hi,
have a look at this little proggie. originally made to get rid of the 
Thumbs.db found everywhere on the disc... Sorry for the german only version but i'd never intended to release it...
As you can see, I first walk though the given start-directory and then through all the others found... May this help you
Code: Select all
;recursives löschen von dateien
;entstanden, um die Datei Thumbs.db loszuwerden
;2006 walker
;
del$=InputRequester("Datei(en) löschen","Bitte zu löschende Datei eingeben","Thumbs.db")
verz$=PathRequester("Bitte Verzeichnis/Laufwerk angeben","c:\")
If verz$<>"" And del$<>""
    NewList dirliste.s()
    aktuellerpfad$=verz$
    count=0
;erst das startverzeichnis durchsuchen
    If ExamineDirectory(0,verz$,"*.*")
        Repeat
            a=NextDirectoryEntry()
            If a=2;verzeichnis
                If DirectoryEntryName()<>"." And DirectoryEntryName()<>".."
                    AddElement(dirliste())
                    dirliste()=verz$+DirectoryEntryName()
                EndIf
            EndIf
            If a=1;datei
                If LCase(DirectoryEntryName())=LCase(del$)
                    DeleteFile(aktuellerpfad$+"\"+DirectoryEntryName())
                    count+1
                EndIf
            EndIf
            
        Until a=0
        x=CountList(dirliste())-1
;dann alle verzeichnisse durchsuchen
        For n = 0 To x ; ForEach() funktioniert NICHT, da anscheinend vorher countlist aufgerufen und intern verwendet wird...
            SelectElement(dirliste(),n)
            aktuellerpfad$=dirliste()
            If ExamineDirectory(1,aktuellerpfad$,"*.*")
                Repeat
                    a=NextDirectoryEntry()
                    If a=2;verzeichnis
                        If DirectoryEntryName()<>"." And DirectoryEntryName()<>".."
                            AddElement(dirliste())
                            dirliste()=aktuellerpfad$+"\"+DirectoryEntryName()
                            x=CountList(dirliste())-1;die anzahl der Schleifendurchläufe anpassen
                        EndIf
                    EndIf
                    If a=1;datei
                        If LCase(DirectoryEntryName())=LCase(del$)
                            DeleteFile(aktuellerpfad$+"\"+DirectoryEntryName())
                            count+1
                        EndIf
                    EndIf
                Until a=0
            Else
                MessageRequester("Fehler im Pfad","Das angegebene Verzeichnis "+aktuellerpfad$ +" kann nicht durchsucht werden...",#PB_MessageRequester_Ok)
            EndIf   
        Next
        MessageRequester("Ergebnis","Es wurden "+Str(count)+ " Dateien gelöscht",#PB_MessageRequester_Ok)
    Else
        MessageRequester("Fehler im Pfad","Das angegebene Verzeichnis "+aktuellerpfad$ +" kann nicht durchsucht werden...",#PB_MessageRequester_Ok)
    EndIf
Else
    MessageRequester("Ergebnis","Es wurden keine Dateien gelöscht",#PB_MessageRequester_Ok)
EndIf
End  
[Edit] should work on Linux too[/Edit]
 
			 
			
					
				
				Posted: Fri Jan 13, 2006 5:20 am
				by Kaiser
				Hey that's awesome Walker, it really helped a lot! 
I guess I'm missing something here but I have no idea about it... lookie, it's your code, a bit modified, but it only adds one tree of the Start Menu folder... the folders inside Programs and Accesories and such are added in the same sub menu... without following hierarchy... got any ideas? :/
Code: Select all
  CreatePopupMenu(1)
  
  NewList dirliste.s() 
  path2$="Path to Start Menu goes here."
  Path$=Path$
  count=0 
  If ExamineDirectory(1,Path$,"*.*") 
    Repeat 
      a=NextDirectoryEntry()
      If a<>0
        If a=2 ;Folder
          If DirectoryEntryName()<>"." And DirectoryEntryName()<>".." 
            AddElement(dirliste()) 
            dirliste()=Path$+DirectoryEntryName() 
          EndIf 
        EndIf 
        If a=1 ;File
          count+1 
        EndIf  
      EndIf 
    Until a=0 
    
    x=CountList(dirliste())-1 
    For n = 0 To x
      SelectElement(dirliste(),n) 
      Path$=dirliste() 
      cnt=0
      k$=StringField(Path$,1,"\") : While k$<>"" : k$=StringField(Path$,cnt,"\") : cnt=cnt+1 : Wend
      GotIt=cnt-2
      OpenSubMenu(StringField(Path$,GotIt,"\"))
      If ExamineDirectory(2,Path$,"*.*")
        Repeat 
          a=NextDirectoryEntry() 
          If a=2 ;Folder
            If DirectoryEntryName()<>"." And DirectoryEntryName()<>".." 
              AddElement(dirliste()) 
              dirliste()=Path$+"\"+DirectoryEntryName() 
              x=CountList(dirliste())-1
            EndIf 
          EndIf 
          If a=1 ;File
            If LCase(Right(DirectoryEntryName(),3))="lnk"
              count+1 
              MenuItem(count,Left(DirectoryEntryName(),Len(DirectoryEntryName())-4))
            EndIf 
          EndIf 
        Until a=0 
        CloseSubMenu()
      Else 
      EndIf    
    Next n
    
    ExamineDirectory(3,path2$,"*.*")   
    Repeat 
      a=NextDirectoryEntry()
      If a<>0
        If a=1 ;File
          If LCase(Right(DirectoryEntryName(),3))="lnk"
            count+1 
            MenuItem(count,Left(DirectoryEntryName(),Len(DirectoryEntryName())-4))
          EndIf 
        EndIf  
      EndIf 
    Until a=0 
    
  EndIf 
  OpenWindow(1,0,0,10,10,0,"lol")
  DisplayPopupMenu(1,WindowID())
 
			 
			
					
				
				Posted: Wed Jan 18, 2006 7:25 am
				by Ziltch
				Is this what you are after?
Code: Select all
NewList DirList.s() 
Global count
Procedure.l  AddDirToMenu(Path$,MenuLevel)
	
	
	If ExamineDirectory(1,Path$,"*.*") 
	
		MenuName$ = StringField(Path$,CountString(Path$,"\")+1,"\") 
		;	Debug "MENU ="+MenuName$
		If count = 0
			CreatePopupMenu(1) 
			MenuName$="Start Menu"
		EndIf
		
		OpenSubMenu(MenuName$)
		Debug "menu ="+path$ + " MenuName=" +MenuName$
		
		DirId = ExamineDirectory(MenuLevel,Path$,"*.*")
		If  DirId
		;	Debug "menu ="+path$ +"   MenuLevel="+Str(MenuLevel)
			DirCount=0
			Repeat 
				DirEntry=NextDirectoryEntry() 
				DirCount=DirCount+1
				Select DirEntry
					Case 0
						break
					Case 2 ;Folder 
						If DirectoryEntryName()<>"." And DirectoryEntryName()<>".." 
							AddElement(DirList()) 
							DirList()=Path$+"\"+DirectoryEntryName() 
							MenuName$ = Left(DirectoryEntryName(),Len(DirectoryEntryName())-4)
							AddDirToMenu(DirList(),MenuLevel+1)
						;	Debug ".MenuLevel = "+Str(MenuLevel) + " DirList="+DirList()
							ExamineDirectory(MenuLevel,Path$,"*.*")
							For a = 1 to DirCount
								NextDirectoryEntry() 
							Next
						;	Debug  Str(Dircount)+" menu item "+MenuName$ ;+ " DirectoryEntryName ="+DirectoryEntryName()
						EndIf 
					Case 1 ;File 
						If LCase(Right(DirectoryEntryName(),3))="lnk" 
							count =count +1 
							MenuItem(count,Left(DirectoryEntryName(),Len(DirectoryEntryName())-4)) 
						;	Debug  " item "+DirectoryEntryName() + " a="+Str(a) + " count = "+Str(count) + " DirEntry="+Str(DirEntry)
							
						EndIf 
				EndSelect
			Until DirEntry=0 
		EndIf    
		
		CloseSubMenu() 
		
	EndIf 
EndProcedure
path2$=GetSpecialFolderLocation(22);  Path to Start Menu goes here. This command is from Droopys lib. Thanks Droopy!
count =0 
AddDirToMenu(Path2$,0)
OpenWindow(1,0,0,10,10,0,"lol") 
DisplayPopupMenu(1,WindowID())