Side note: I know my status bar is lame and will just continuously paint the bar over and over but it should also display the number of files processed so it would give the user something to look at
Code: Select all
;
;
; Program GetFileInfo
;
; Program to get information on files from a specific folder
; Written 5/10/2025
; Written by Me
;
;
EnableExplicit
Structure FileInfoStructure
NameOfFile.s
PathOfFile.s
CreateDateOfFile.i
AccessDateOfFile.i
ModifiedDateOfFile.i
SizeOfFile.i
AttributesOfFile.i
EndStructure
Structure DirectoryStructure
NameOfFolder.s
FolderID.i
Processed.b
Comment.s
EndStructure
Global LogFileName.s, Log, CountDone, CountProgressBarGadget
Global eWaitWindow.i, eType.i, gActiveGadget.i, ProgressBarWindow.i = 0, gProgressBarGadget.i = 0, gProgressBarGadgetLevel.i = 50
Global gDoneYes.i = 0, Status_Max = 1000, FileCount, GlobalDir.s
Global DirectoryNumber, StartPath.s, FileFilter.s, path.s, Pattern.s
Global NewList FileInfo.FileInfoStructure()
Global NewList Directories.DirectoryStructure()
Enumeration
#MAIN_FORM
#STATUS_BAR
#TEXT
EndEnumeration
Procedure THR_increment(*para)
Repeat
Protected n
n = n + 1
LogSomething("In THR_increment: n=" + Str(n) + " FileCount = " + Str(FileCount) + " gDoneYes = " + Str(gDoneYes) + ".")
SetGadgetText(#TEXT,"Processed "+Str(FileCount)+" files.")
StatusBarProgress(#STATUS_BAR,0,n,#PB_StatusBar_BorderLess,0,Status_Max)
If n>Status_Max
n = 0
EndIf
Delay(100)
Until gDoneYes = #True
EndProcedure
Define.s FullPathName, NewFolder, CurrentFolderName, FileToSave
Define FoundAnotherOne, AllFoldersProcessed.b, CurrentFolder, *ActiveElement, *TrainTrackElement, UserResponse, MissionComplete.b, MainThread, StatusThread
Procedure.s WalkRecursive(dir,path.s,Pattern.s="\.txt$")
While NextDirectoryEntry(dir)
If DirectoryEntryType(dir)=#PB_DirectoryEntry_Directory
If DirectoryEntryName(dir)<>"." And DirectoryEntryName(dir)<>".."
If ExamineDirectory(dir+1,path+DirectoryEntryName(dir),"")
AddElement(Directories())
Directories()\NameOfFolder = path + "\" + DirectoryEntryName(dir)
Directories()\Processed = #False
WalkRecursive(dir+1,path+DirectoryEntryName(dir)+"\",Pattern)
FinishDirectory(dir+1)
Else
LogSomething("Error in "+path+DirectoryEntryName(dir))
EndIf
EndIf
Else ; e.g. #PB_DirectoryEntry_File
FileCount + 1
LogSomething("Got file number " + Str(FileCount) + ": " + DirectoryEntryName(dir) + ".")
AddElement(FileInfo())
FileInfo()\NameOfFile = DirectoryEntryName(dir)
FileInfo()\PathOfFile = path
FileInfo()\CreateDateOfFile = DirectoryEntryDate(dir, #PB_Date_Created)
FileInfo()\ModifiedDateOfFile = DirectoryEntryDate(dir, #PB_Date_Modified)
FileInfo()\AccessDateOfFile = DirectoryEntryDate(dir, #PB_Date_Accessed)
fileinfo()\SizeOfFile = DirectoryEntrySize(dir)
Fileinfo()\AttributesOfFile = DirectoryEntryAttributes(dir)
EndIf
Wend
EndProcedure
Procedure DoTheWalk(*ThreadNum)
LogSomething("I'm in the thread, 5x5, reticulating splines: " + GlobalDir)
FileCount = 0
ExamineDirectory(1, GlobalDir, "*.*")
WalkRecursive(1, GlobalDir, "*.*")
LogSomething("OK, we're done now... exiting I think...")
gDoneYes = #True
EndProcedure
gDoneYes = #False
GetLogFile()
LogSomething("Program starting...")
StartPath = InputRequester("Path to search", "Please enter the path to start the file search","C:\")
LogSomething("User input the path " + #DQUOTE$ + StartPath + #DQUOTE$)
If Right(StartPath, 1) <> "\"
StartPath + "\"
EndIf
GlobalDir = StartPath
OpenWindow(#MAIN_FORM, 0, 0, 300, 100, "Getting File Info", #PB_Window_ScreenCentered)
TextGadget(#TEXT, 10, 10, 280, 30, "")
CreateStatusBar(#STATUS_BAR, WindowID(#MAIN_FORM))
AddStatusBarField(#PB_Ignore)
StatusThread = CreateThread(@THR_increment(),0)
MainThread = CreateThread(@DoTheWalk(), 1)
LogSomething("Now waiting on the thread to complete.")
WaitThread(MainThread)
gDoneYes = #True
LogSomething("Thread complete. Moving on to saving the file.")
KillThread(StatusThread)
CloseWindow(#MAIN_FORM)
Thank you!