QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: alexpro1ny on February 23, 2018, 03:23:51 pm
-
Hi,
I used to write my code using Professional Basic (QBX) 7.1
It was a nice program since you could test and debug your code within the compiler without having to make a .exe file first.
I have been using QB64 to convert some of my programs so they would work in Windows 10 and love that it is available. Without QB64, I'd have to run everything in my Virtual XP window.
I installed your latest version 1.2 and found that it doesn't like the DIR$ command that is a valid function within QBX. It looks like _DIR$ is in QB64 but it doesn't work the same as DIR$.
For example, if I want to see a list of text files, I can do the following in QBX
DIM dskfile$(200)
filespec$ = "*.txt"
a$ = _DIR$(filespec$)
IF LEN(a$) = 0 THEN GOTO nofilesexist
dskfile = 1
dskfile$(dskfile) = a$
DO
b$ = DIR$
IF LEN(b$) = 0 THEN GOTO filelistdone
dskfile = dskfile + 1
dskfile$(dskfile) = b$
LOOP
GOTO filelistdone
nofilesexist:
STOP
filelistdone:
FOR n = 1 TO dskfile
PRINT dskfile$(n)
NEXT n
PRINT dskfile; "files exist"
Using this method I can store into my array all the files that are named .txt
Is there any simple way for me to do the same in QB64?
Thanks,
Alex
-
There's a DIR$() function written by Ted at http://qb64.org/wiki/FILES (http://qb64.org/wiki/FILES#Alternative_file_list_solutions) - a fine workaround.
-
DIM dskfile$(200)
filespec$ = "*.txt"
' Caution. If you already have a file named tmp.txt, this next statement will overwrite a file named tmp.txt in your current directory.
SHELL _HIDE "dir /b " + filespec$ + ">tmp.txt"
' The /b switch returns only the file names.
OPEN "tmp.txt" FOR INPUT AS #1
DO UNTIL EOF(1)
LINE INPUT #1, a$
dskfile = dskfile + 1
dskfile$(dskfile) = a$
LOOP
FOR i = 1 TO dskfile
PRINT i; dskfile$(i)
NEXT
-----------------------------------
Also, check out _FILEESIST in the WIKI: https://qb64.org/wiki
Pete :)
-
Next solution is adding as .BI and .BM files this program https://www.qb64.org/forum/index.php?topic=87.0 - then array named ShortNameFile return file names in format 8.3 and array FileNames return all files in long format. Use SUB named Filtruj for using mask. If you want, I will write to you tomorrow how to use it without selecting __Files$ for .txt files in actual directory. This program is solution for Unicode uncompability, because if you use SHELL and DIR for files named in unicode, then is returned unusable result for you.
-
There's a DIR$() function written by Ted at http://qb64.org/wiki/FILES (http://qb64.org/wiki/FILES#Alternative_file_list_solutions) - a fine workaround.
Thanks.. that looks like the ticket I've been looking for.
-
DIM dskfile$(200)
filespec$ = "*.txt"
' Caution. If you already have a file named tmp.txt, this next statement will overwrite a file named tmp.txt in your current directory.
SHELL _HIDE "dir /b " + filespec$ + ">tmp.txt"
' The /b switch returns only the file names.
OPEN "tmp.txt" FOR INPUT AS #1
DO UNTIL EOF(1)
LINE INPUT #1, a$
dskfile = dskfile + 1
dskfile$(dskfile) = a$
LOOP
FOR i = 1 TO dskfile
PRINT i; dskfile$(i)
NEXT
-----------------------------------
Also, check out _FILEESIST in the WIKI: https://qb64.org/wiki
Pete :)
Thanks Pete... I used to do it like this before the DIR$ function was added. It worked but I try to avoid using SHELL as much as possible. Thanks though.
-
This is one of my old wishes ... doing it in memory with a built-in function instead of using temp files on disk. So much memory to use these days!
-
FOUND IT!!!! Kernel32 DLL access using findFirstFile
I used basically the same code in QB45 until I bought QB7.1 Pro. 12 years ago I bought Power Basic 4 and it has the DIR$ ala QB7.1. I want to use system calls if possible and not temp files. It can be adapted to OSx (BSD) and Linux as well. Just add conditionals for compiling.
Cromaglious
Robi
-
http://qb64.freeforums.net/thread/63/file-directory-listing-arrays -- An easy method to get both file and directory listings into arrays.
-
FOUND IT!!!! Kernel32 DLL access using findFirstFile
I used basically the same code in QB45 until I bought QB7.1 Pro. 12 years ago I bought Power Basic 4 and it has the DIR$ ala QB7.1. I want to use system calls if possible and not temp files. It can be adapted to OSx (BSD) and Linux as well. Just add conditionals for compiling.
Cromaglious
Robi
Thanks for sharing, Cromaglious. I didn't know that existed in the API.
Welcome to the forum!
Fellippe.
-
There is one thing to be careful of with FindFirstFile: https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-findfirstfilea
If you are writing a 32-bit application to list all the files in a directory and the application may be run on a 64-bit computer, you should call the Wow64DisableWow64FsRedirection function before calling FindFirstFile and call Wow64RevertWow64FsRedirection after the last call to FindNextFile.
QB64 is a 32-bit application. If you're going to share your code with others, they might get run it on 64-bit computers, so be certain to make the additional function calls so you won't generate errors.
-
Hi Guys
just to grab an information...
in DOS/WindowSes you must use FindFirstFile API function, and in Mac Oses and in Linux (different distroes) is there a similar API ?
It goes around some my wishes for the future QB64 enpowerment https://www.qb64.org/forum/index.php?topic=714.msg6001#msg6001 (https://www.qb64.org/forum/index.php?topic=714.msg6001#msg6001)
My wishlist:
* full compatibility of QB64 with local language of user
* completed set of functions/keywords to manage files
* a debug session with interpeter (real or emulated like in TurboBasic)--> can be used vWatch to get this?
* a well documented set of functions/keywords to manage hardware at low level
* a more integrated GUIFormer and EventDriven editor
* a set of webSubscript functions
* a database system....
and more and more....
Great the QB64 community!
Thanks to read
PS
I know nothing about MacOs (except that is the first windowed OS if you don't remember GEM on old 5.25 FDD, and it manages in different mode the RAM allocation for calculation of offset) and Linux (except that it is the realm of serious C programmers and some C++ programmers) also if I imagine that also these OSes have their API.
-
Hi Guys
just to grab an information...
in DOS/WindowSes you must use FindFirstFile API function, and in Mac Oses and in Linux (different distroes) is there a similar API ?
It goes around some my wishes for the future QB64 enpowerment https://www.qb64.org/forum/index.php?topic=714.msg6001#msg6001 (https://www.qb64.org/forum/index.php?topic=714.msg6001#msg6001)
My wishlist:
* full compatibility of QB64 with local language of user
* completed set of functions/keywords to manage files
* a debug session with interpeter (real or emulated like in TurboBasic)--> can be used vWatch to get this?
* a well documented set of functions/keywords to manage hardware at low level
* a more integrated GUIFormer and EventDriven editor
* a set of webSubscript functions
* a database system....
and more and more....
Great the QB64 community!
Thanks to read
PS
I know nothing about MacOs (except that is the first windowed OS if you don't remember GEM on old 5.25 FDD, and it manages in different mode the RAM allocation for calculation of offset) and Linux (except that it is the realm of serious C programmers and some C++ programmers) also if I imagine that also these OSes have their API.
Look above, reply #8. It uses POSIX for reading files and directories, which is used for any system that QB64 is used on. Linux, Mac, Windows.... You're good to good!