_Title "Count BAS files from a start Directory" ' b+ 2021-11-04
' direntry.h needs to be in QB64.exe folder, see below for a commented copy
ReDim Shared BasList$
(10000) 'store our Bas pathed Files here
FullPathedDir$ = "C:\Users\marka\downloads" ' <<<<<<<<<<<<< change this line to top directory of your search for
' best results use places where Windows lets you write bas files.
FindAndCountBasFileFrom FullPathedDir$
Print " Grand Total .bas ="; GrandTotal
Print FullPathedDir$
+ "\Bas List.txt file is ready."
Sub FindAndCountBasFileFrom
(startDir$
) If Right$(startDir$
, 1) <> "\" Then startDir$
= startDir$
+ "\" 'Print "Changing Directory to "; startDir$; ""
GetLists startDir$, ds(), fs()
'Print startDir$ + " .bas Files:"
GrandTotal = GrandTotal + 1
Print GrandTotal
, startDir$
+ fs
(i
) BasList$(GrandTotal) = startDir$ + fs(i)
'If i Mod 20 = 19 Then Print "Press any to cont..": Sleep
'Print
'Print startDir$ + " Sub-Directories: zzz...": Sleep
newD$ = startDir$ + ds(j)
'Print "Press any to FindAndCountBasFileFrom " + newD$ + "... zzz": Sleep
FindAndCountBasFileFrom newD$
'Print "Press any to cont...": Sleep
' !!! For this sub to work the _CWD has to be the Search Directory! !!!
' Thanks SNcNeill ! for a cross platform method to get file and directory lists
'put this block in main code section of your program close to top
'' direntry.h needs to be in QB64 folder '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
'DECLARE CUSTOMTYPE LIBRARY ".\direntry"
' FUNCTION load_dir& (s AS STRING)
' FUNCTION has_next_entry& ()
' SUB close_dir ()
' SUB get_next_entry (s AS STRING, flags AS LONG, file_size AS LONG)
'END DECLARE
DirCount = 0: FileCount = 0
length = has_next_entry
get_next_entry nam$, flags, file_size
DirCount = DirCount + 1
DirList(DirCount) = nam$
FileCount = FileCount + 1
'Print Left$(SearchDirectory, Len(searchDiretory) - 1)
'getting allot of wierd misfires
FileList(FileCount) = nam$
'close_dir 'move to after end if might correct the multi calls problem
close_dir 'this might correct the multi calls problem
' Remove comments below and save as direntry.h
' in your QB64.exe folder if you don't have it already
'=============================================================
'#include <dirent.h>
'#include <sys/stat.h>
'#include <unistd.h>
'const int IS_DIR_FLAG = 1, IS_FILE_FLAG = 2;
'DIR *pdir;
'struct dirent *next_entry;
'struct stat statbuf1;
'char current_dir[FILENAME_MAX];
'#ifdef QB64_WINDOWS
' #define GetCurrentDir _getcwd
'#else
' #define GetCurrentDir getcwd
'#endif
'int load_dir (char * path) {
' struct dirent *pent;
' struct stat statbuf1;
'//Open current directory
'pdir = opendir(path);
'if (!pdir) {
'return 0; //Didn't open
'}
'return -1;
'}
'int has_next_entry () {
' next_entry = readdir(pdir);
' if (next_entry == NULL) return -1;
' stat(next_entry->d_name, &statbuf1);
' return strlen(next_entry->d_name);
'}
'void get_next_entry (char * nam, int * flags, int * file_size) {
' strcpy(nam, next_entry->d_name);
' if (S_ISDIR(statbuf1.st_mode)) {
' *flags = IS_DIR_FLAG;
' } else {
' *flags = IS_FILE_FLAG;
' }
' *file_size = statbuf1.st_size;
' return ;
'}
'void close_dir () {
' closedir(pdir);
' pdir = NULL;
' return ;
'}
'int current_dir_length () {
' GetCurrentDir(current_dir, sizeof(current_dir));
' return strlen(current_dir);
'}
'void get_current_dir(char *dir) {
' memcpy(dir, current_dir, strlen(current_dir));
' return ;
'}