Page 1 of 1
Working through a complete directory structure/tree.
Posted: Thu Aug 14, 2008 7:28 pm
by Arcee_uk
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
Posted: Fri Aug 22, 2008 10:54 pm
by Hroudtwolf
Hi,
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
Regards
Wolf