File search in QB without crash
Posted: Sat Jul 10, 2021 9:44 pm
Pardon me for my crazy code below, but one thing I have an issue with is file scanning.
I'm making an application strictly for MS-DOS with QB 4.x that is to scan the entire hard drive for a particular file. The problem is the program bombs with the index of the array index being too high or insufficient string space.
Anyways, for those who don't want to go through my code, I'll explain in pseudo code what happens:
As you can see, in my code, if there are a ton of folders like many computers will have today, my program will ultimately crash due to insufficient string space.
And I feel my options will look bleak because my target is old computers without much memory or disk space.
I see my choices are as follows:
1. Require user to have several megs of XMS memory, or
2. Thrash the user's disk as directory entries are constantly written to or read from it, or
3. somehow wipe out sections of the folder array and somehow fill them with new directory entries.
Any suggestions?
And there's my crummy code below.
I'm making an application strictly for MS-DOS with QB 4.x that is to scan the entire hard drive for a particular file. The problem is the program bombs with the index of the array index being too high or insufficient string space.
Anyways, for those who don't want to go through my code, I'll explain in pseudo code what happens:
Code: Select all
Assume our X filesystem has this directory tree:
In X:
Folder: QB
Folder: WIN
In X:\QB
Folder: ASIC
Folder: 45
In X:\WIN
Folder: SYS
And no folders in either ASIC, 45, or SYS.
Pseudo code:
1. Build empty array of x bytes to hold all folders.
2. Set 2 variables: s = number of folders found, p = our progress in folders
2. Set 1st index (s=1) of that array to root drive. example: "X:" (# folders found=1)
3. Load 1st index (p=1) and get directory list (= DIR X: in DOS)
4. Array now contains:
Index 1 = X:
index 2 = X:\QB
Index 3 = X:\WIN
5. s = 3 (as there's 3 entries in the folder array). increment p and get next list (= DIR X:\QB)
6. Array now contains:
Index 1 = X:
index 2 = X:\QB
Index 3 = X:\WIN
index 4 = X:\QB\ASIC
index 5 = X:\QB\45
7. s = 5 (as there's 5 entries in the folder array). increment p and get next list (= DIR X:\WIN)
8. Array now contains:
Index 1 = X:
index 2 = X:\QB
Index 3 = X:\WIN
index 4 = X:\QB\ASIC
index 5 = X:\QB\45
index 6 = X:\WIN\SYS
9. s = 6 (as there's 6 entries in the folder array). increment p and get next list (= DIR X:\QB\ASIC)
....Now this time the list won't grow because the remaining folders don't have folders inside of them. p will keep incrementing until it reaches 6 them the program ends.
And I feel my options will look bleak because my target is old computers without much memory or disk space.
I see my choices are as follows:
1. Require user to have several megs of XMS memory, or
2. Thrash the user's disk as directory entries are constantly written to or read from it, or
3. somehow wipe out sections of the folder array and somehow fill them with new directory entries.
Any suggestions?
And there's my crummy code below.
Code: Select all
folder$() variable represents all folders collected so far.
myfol$ = RTRIM$(myfol$)
x.func = 0: x.filespec = myfol$ + "\*.*" + CHR$(0): x.mask = &H1F: xx& = 0
DO
CALL runcode: obj$ = LEFT$(x.fname, x.flen)
IF x.fattr = 16 THEN
IF obj$ <> "." AND obj$ <> ".." THEN
folct& = folct& + 1: folders$(folct&) = myfol$ + "\" + obj$
END IF
ELSE
mat$ = LEFT$(x.fname, x.flen)
IF RTRIM$(UCASE$(mat$)) = RTRIM$(UCASE$(matf$)) THEN findinfol% = 1: EXIT DO
END IF
xx& = xx& + 1
LOOP UNTIL x.errc > 0 OR xx& > 32766