Getting files one by one from folder with specific file extension
Posted: Tue Aug 22, 2023 7:36 am
Heya, guys,
I have a folder full of .csv and .txt files and I want to store each .csv file in an array with the full path to it.
First, I open a file selector so that the user clicks in a file from the folder to set it as the current folder.
But, the:
returns zero, so, it is not working.
What is wrong with my code?
Thanks!
I have a folder full of .csv and .txt files and I want to store each .csv file in an array with the full path to it.
First, I open a file selector so that the user clicks in a file from the folder to set it as the current folder.
But, the:
Code: Select all
Debug "NextDirectoryEntry(1):"+Str(NextDirectoryEntry(1))
What is wrong with my code?
Code: Select all
Procedure batch_reprocess_open_reprocess_save()
; Select the .csv source folder
file$=OpenFileRequester("Select a .csv file to know the source folder", "", "csv (.csv)|*.csv", 0)
If file$=""
MessageRequester("Warning!","No file selected.",#PB_MessageRequester_Warning)
ProcedureReturn #False
EndIf
; If no .csv file is found in the folder
flag=ExamineDirectory(1,GetCurrentDirectory(),".csv")
FinishDirectory(1)
If flag=#False
MessageRequester("Warning!","No file found.",#PB_MessageRequester_Warning)
ProcedureReturn #False
EndIf
; count the .csv number of files
counter=0
flag=ExamineDirectory(1,GetCurrentDirectory(),".csv")
Debug "ExamineDirectory:"+Str(flag)
Debug "NextDirectoryEntry(1):"+Str(NextDirectoryEntry(1))
While NextDirectoryEntry(1)=#True
counter+1
Wend
FinishDirectory(1)
Debug "counter:"+Str(counter)
Debug "GetCurrentDirectory():"+GetCurrentDirectory()
; Store all .csv files in the array
Dim files_to_reprocess$(counter)
flag=ExamineDirectory(1,GetCurrentDirectory(),".csv")
For f=1 To counter
flag=NextDirectoryEntry(1)
file$=DirectoryEntryName(1)
files_to_reprocess$(f)=file$
Next f
FinishDirectory(1)
SortArray(files_to_reprocess$(),#PB_Sort_Ascending|#PB_Sort_NoCase,1,counter)
For f=1 To counter
Debug Str(f)+"->"+files_to_reprocess$(f)
Next f
EndProcedure
Thanks!