OPTION _EXPLICIT 'Text Fetch.bas started b+ 2019-11-12 from other work with Dirs and Files loading
': This program uses
': InForm - GUI library for QB64 - v1.0
': Fellippe Heitor, 2016-2019 - fellippe@qb64.org - @fellippeheitor
': https://github.com/FellippeHeitor/InForm
'-----------------------------------------------------------
': Controls' IDs: ------------------------------------------------------------------
IF ENVIRON$("TEMP") <> "" THEN 'Thanks to Steve McNeill use user temp files directory ELSE 'Thanks to Steve McNeill this should be very unlikely tmpDir = "C:\temp"
': External modules: ---------------------------------------------------------------
'$INCLUDE:'InForm\InForm.ui'
'$INCLUDE:'InForm\xp.uitheme'
'$INCLUDE:'Text Fetch.frm'
ResetList ListTxt
b$ = GetItem$(ListFile, i)
AddItem ListTxt, GetItem$(ListFile, i)
Caption(lbTxt) = "Selected Text (in Clipboard):"
SUB loadDirsFilesList
'f or this form Caption
(lbCWD
) = "Current Directory: " + _CWD$ loadDIR Dir()
ResetList ListDirs
AddItem ListDirs, Dir(i)
loadFiles File()
ResetList ListFiles
AddItem ListFiles, File(i)
'This SUB will take a given N delimited string, and delimiter$ and create an array of N+1 strings using the LBOUND of the given dynamic array to load.
'notes: the loadMeArray() needs to be dynamic string array and will not change the LBOUND of the array it is given. rev 2019-08-27
curpos
= 1: arrpos
= LBOUND(loadMeArray
): LD
= LEN(delim
) dpos
= INSTR(curpos
, SplitMeString
, delim
) loadMeArray
(arrpos
) = MID$(SplitMeString
, curpos
, dpos
- curpos
) arrpos = arrpos + 1
curpos = dpos + LD
dpos
= INSTR(curpos
, SplitMeString
, delim
) loadMeArray
(arrpos
) = MID$(SplitMeString
, curpos
)
END FUNCTION 'last line 317 + CRLF always added at end of .bas files
tmpFile = tmpDir + "\DIR$INF0.INF" 'aha!, not a fully pathed file to user directory but here is good!
SHELL _HIDE "DIR /a:d >" + tmpFile
'get directories but have to do a little pruning Index% = -1
d$
= _TRIM$(rightOf$
(fline$
, "<DIR>")) Index% = Index% + 1
fa(Index%) = d$
tmpFile = tmpDir + "\FILE$INF0.INF" 'aha!, not a fully pathed file to user directory but here is good!
SHELL _HIDE "DIR *.* /a:-d /b /o:-gen > " + tmpFile
Index% = -1
Index% = Index% + 1
': Event procedures: ---------------------------------------------------------------
loadDirsFilesList
SUB __UI_BeforeUpdateDisplay
'This event occurs at approximately 30 frames per second.
'You can change the update frequency by calling SetFrameRate DesiredRate%
'If you set __UI_UnloadSignal = False here you can
'cancel the user's request to close.
dir$ = GetItem$(ListDirs, Control(ListDirs).Value)
Caption
(lbCWD
) = "Current Directory: " + _CWD$ loadDirsFilesList
fi$ = GetItem$(ListFiles, Control(ListFiles).Value)
fs$ = fileStr$(fi$)
ResetList ListFile
AddItem ListFile, fa$(i)
'clear
Caption(lbStart) = "Line Start"
Caption(lbEnd) = "Line End"
Caption
(lbFile
) = "Selected File: Path = " + _CWD$ + ", Name = " + fi$
value = Control(ListFile).Value
Caption
(lbStart
) = STR$(value
) + " Start Line" IF VAL(Caption
(lbStart
)) - VAL(Caption
(lbEnd
)) > 0 THEN loadText
value = Control(ListFile).Value
Caption
(lbEnd
) = STR$(value
) + " End Line" IF VAL(Caption
(lbEnd
)) - VAL(Caption
(lbStart
)) > 0 THEN loadText
'This event occurs right before a control loses focus.
'To prevent a control from losing focus, set __UI_KeepFocus = True below.
'When this event is fired, __UI_KeyHit will contain the code of the key hit.
'You can change it and even cancel it by making it = 0
'============================================== Failed Again! but took longer this time =============================================
SUB loadDirsFilesList_BLAHHHHHHHHHHHHHHH
'modified Steve's that uses 'Below needed for Steves load dirs and files which fails ????? for some strange reason
''''this needs to be somewhere QB64 can find, I have direntry.h in file folder as well as QB64.exe root
Caption
(lbCWD
) = "Current Directory: " + _CWD$ nDirs = GetCurDirLists(Dir(), File())
cntTrys = cntTrys + 1
ResetList ListDirs
AddItem ListDirs, Dir(i)
ResetList ListFiles
AddItem ListFiles, File(i)
' once again this thing from Steve fails, this time it got further than with my other test
DirCount = 0: FileCount = 0
lengtht = has_next_entry
get_next_entry nam$, flags, file_size
'IF (flags AND 1) OR _DIREXISTS(d$ + nam$) THEN
DirCount = DirCount + 1
DirList(DirCount) = nam$
'ELSEIF (flags AND 2) OR _FILEEXISTS(d$ + nam$) THEN
FileCount = FileCount + 1
FileList(FileCount) = nam$
close_dir
GetCurDirLists% = DirCount