The DIR$ function adapted from PDS (7.1) returns a filename or a list when more than one exist. The file spec can use a path and/or wildcards.Code: QB64: [Select]
file$ = DIR$(spec$) 'use a file spec ONCE to find the last file name listed file$ = DIR$("") 'use an empty string parameter to return a list of files! PRINT file$, SHARED DIRCount% 'returns file count if desired CLOSE #ff% Index% = Index% + 1 DIRCount% = Index% 'SHARED variable can return the file count CLOSE #ff% KILL TmpFile$ DIR$ = DirList$(Index%)
There is a non-Windows solution too but a little more work.@bplus Guess what? Mine is cross-platform ;) Works on Linux, Mac, and Windows. All the same code.
@bplus Guess what? Mine is cross-platform ;) Works on Linux, Mac, and Windows. All the same code.
Obligatory friendly reminder that Linux is case sensitive for file names, so "dir *.BAS" won't match "foo.bas".@luke Yes, of course. I didn't mean that "dir /b *.BAS" was cross-platform. Only that the pipecom library was :)
Also on Linux and MacOS the default output is plain filenames, "ls -l" is needed for a full listing with metadata.
Thanks for your suggestion. The issue is resolved.@sparjolly Glad to hear!
Oh cool!@bplus I hadn't posted it. I have been keeping it on the Discord server only while I've been testing it across platforms. Although, I reckon I could make a post for it.
@SpriggsySpriggs had you posted this? I must have missed.
@SpriggsySpriggs Looking at best answer it's no different than@doppler
DIM F AS STRING
CHDIR "c:\qb64\my programs"
shell "dir /b *.bas | clip"
f=_clipboard$
PRINT F
But which way would be faster (by code execution time) ? Which one could hold more data ? (me thinks windows clipboard)
@SpriggsySpriggs Looking at best answer it's no different than
DIM F AS STRING
CHDIR "c:\qb64\my programs"
shell "dir /b *.bas | clip"
f=_clipboard$
PRINT F
But which way would be faster (by code execution time) ? Which one could hold more data ? (me thinks windows clipboard)
@doppler man! this is so simple for 2-3 years I've been looking for something half this good then Spriggsy shows a real break through and then you show a better! You guys get my nomination for Tip of the Month!@bplus My main complaint against using "clip" is that in doing so you are possibly showing the user how your code works which is not always something you want to do. You really want your functions to be hidden because if they just start seeing console output in their clipboard then the magic is lost. Also, like I was telling doppler, you don't want to overwrite the clipboard as many people don't have Windows 10 and those who do haven't enabled Clipboard History so you would be overwriting something they might want on the clipboard. If you are going to overwrite their clipboard it might be wise to tell them first or read the clipboard into a string, do your thing, then copy it back to the clipboard.