I need to try and get the complete file structure of a directory so I can work on the files within it. Each file is going to be renamed based up the directories which it is located under. So, for example Data/Images/Icons/Window1/ May have all it's files renamed to "Window1_Iconsxxx.jpg"
---
Found something that works. Searched for Recursive directories...
Arcee
Working through a complete directory structure/tree.
- Hroudtwolf
- Addict
- Posts: 803
- Joined: Sat Feb 12, 2005 3:35 am
- Location: Germany(Hessen)
- Contact:
Hi,
Try this...
Regards
Wolf
Try this...
Code: Select all
; Hroudtwolf
; 22/08/2008
; PureBasic 4.x
; Linux, Window, OS-X
Structure tDIRECTORYENTRY
sName.s
lType.l
EndStructure
Procedure RecursiveDirectoryScan ( sPath.s , sPattern.s , FileList.tDIRECTORYENTRY () )
Protected lDirID.l
lDirID = ExamineDirectory ( #PB_Any , sPath , sPattern )
If Not lDirID
ProcedureReturn #False
EndIf
While NextDirectoryEntry (lDirID)
If Not (DirectoryEntryName ( lDirID) = "." Or DirectoryEntryName (lDirID) = ".." )
AddElement (FileList ())
FileList ()\sName = sPath + "\" + DirectoryEntryName ( lDirID )
FileList ()\lType = DirectoryEntryType ( lDirID )
EndIf
If DirectoryEntryType ( DirID ) = #PB_DirectoryEntry_Directory And Not ( DirectoryEntryName ( lDirID ) = "." Or DirectoryEntryName ( lDirID ) = ".." )
If Not RecursiveDirectoryScan ( sPath + "\" + DirectoryEntryName ( lDirID ) , sPattern , FileList () )
ProcedureReturn #False
EndIf
EndIf
Wend
FinishDirectory ( lDirID )
ProcedureReturn #True
EndProcedure
NewList MyFileList.tDIRECTORYENTRY ()
Dim sType .s (2)
sType (#PB_DirectoryEntry_File) = "[File ]"
sType (#PB_DirectoryEntry_Directory) = "[Directory]"
RecursiveDirectoryScan ( "C:\Programmierung\SourceArchiv" , "*.*" , MyFileList () )
ForEach MyFileList ()
Debug sType ( MyFileList ()\lType ) + Space (10) + MyFileList ()\sName
Next
Wolf