QB64.org Forum
Active Forums => Programs => Topic started by: SMcNeill on July 27, 2017, 09:00:57 am
-
Lots of folks like to ask for a way to easily grab the contents of a directory and import a list of the contents of that directory into their programs, so for them, I introduce my little File Grab Library.
'$INCLUDE:'Filegrab.BI'
SelectFile
_CWD$, "*.*", Results
()
'$INCLUDE:'Filegrab.BM'
As you can see, usage is fairly straight forward.
Extract to your QB64 folder.
Include the header.
Include the footer.
REDIM an array to hold the results.
Call the routine with SelectFile _CWD$, "*.*", Results(),
SelectFile is the name of the routine.
First Parameter _CWD$ can be replaced with whatever directory you want the contents of.
Second Parameter "*.*" is the filter of whatever you want for that directory. Use "*.txt" for a listing of all text files, for example.
Third Parameter Results() is the REDIM array which you use to store the results of the file listing.
Works on Windows, Linux, and Mac.
-
Thanks that is one I have been currently wanting!
-
May I ask a maybe dumb question? ...well I can ask ;-))
What is an .h and .BM file?
I do remember .BI files.
-
Hi Steve. Its works good, but could you still add output in 8.3 format? I certainly do not have to explain why. Thank you for answer.
-
A .h file is an external C++ header file you attach to your QB64 programs via /wiki/index.php/DECLARE_LIBRARY.html]DECLARE LIBRARY (https://qb64.org/wiki/www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there). It'll contain procedures and functions that'll extend QB64's capabilities.
A .BM or a .BI (or whatever other extension you desire, really) is a plain text QB64 source code file. Convention has it [citation needed] that if your library requires SHARED variables, CONSTs, TYPES, external helper libraries - that is, code that needs to be in the beginning of a program, you'll add these to a .BI module to be included at the top. Then your SUBs and FUNCTIONs will be in the .BM (M for methods, I guess?) that the end-user will $INCLUDE at the bottom.
This is especially so because you can't have stray code after your block of SUB/FUNCTIONs begins.
'include .BI
'your code
'include .BM
'your subs
-
May I ask a maybe dumb question? ...well I can ask ;-))
What is an .h and .BM file?
I do remember .BI files.
QB64 requires SUB/FUNCTION statements to come at the end of our code (whereas QB45 would allow them anywhere), so include files need to be broken into two parts -- the part which goes at the top of the code (DIM statements, TYPEs, etc), and the part that goes at the end of the code (the SUB and FUNCTION/).
BI files are just an extension to say, "Include this one first" and BM files are just a convention to say, "Include this last, at the end of the file."
*******************
As for .h files,they're C-code which we can use to expand C-routines for use in QB64, which usually has to be linked to with DECLARE LIBRARY.
(Felippe types faster than me and beat me to the answer.) ;)
-
Thanks Steve and Fellippe, this is very helpful for me getting up to speed. So that is why the other (BM) is below! nice mnemonic ;)
OK I am trying to test the demo and have error about finding the .BI but, as I show, it is in the expected directory/folder, I think.
Any ideas the problem?
see screen shot
-
Make the path relative to the .BI file:
In the DECLARE LIBRARY block inside Filegrab.BI add .\ before the name of the library.
-
Hi Fellippe and all,
Nope, ./ actually messes up the pathed filename that QB64 says it can't find in the error message.
Does QB64 have any problems with spaces in pathed filename or length of the pathed filename?
Append:
"In the declare library bi" oh, in the BI file...
-
In the DECLARE LIBRARY block inside Filegrab.BI add .\ before the name of the library.
or copy .BM and .BI files direct to directory with your QB64 installation.
-
Direntry.h needs to be in the root qb64 folder with qb64.exe to work properly. The error is probably there.
(I'd suggest extracting to the main QB64 folder once for testing to make certain it works as advertised on your system. Everything after that is just adjusting paths to point to the correct places.)
-
Thanks all,
Yep! I copied everything to QB64.exe folder and the demo .bas runs fine from there AND it now runs fine from the grabfile Folder as well.
Maybe just the .h file? I will try combos and learn a lesson! :) of where what is needed.
-
Just checked: if you make the path relative to the .BI file, direntry.h can be in the same folder as the .BI, even if this is not qb64's main folder:
@Steve: looks like a simple enough patch to your lib to prevent future issues for others who decide to try it.
-
I can confirm Fellippe's fix.
I deleted all the grab files in QB64.exe folder, made the change in the .BI ./ and all worked! :)
Append:
hmm... ./ or .\ ?? in Windows I don't think it matters, but I see ./ in Windows paths.
-
Doesn't matter.