Author Topic: Browsing Directories / files using Steve´s library  (Read 3642 times)

0 Members and 1 Guest are viewing this topic.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Browsing Directories / files using Steve´s library
« on: July 08, 2018, 06:57:14 am »
Hi, I'm just very limited in time, so I write this program for longer than usual. I just did not get to test it in Linux. Select and run any file. Quit it using Esc. Query for Steve: Exists a program that returns disk names usable in  both OS - windows and linux?

Code: QB64: [Select]
  1. 'files/directories list using Steve library (u.s. chars only)
  2.     FUNCTION load_dir& (s AS STRING)
  3.     FUNCTION has_next_entry& ()
  4.     SUB close_dir ()
  5.     SUB get_next_entry (s AS STRING, flags AS LONG, file_size AS LONG)
  6. SCREEN _NEWIMAGE(800, 600, 32)
  7.  
  8.  
  9. start:
  10.  
  11.  
  12. REDIM Dir(0) AS STRING, File(0) AS STRING
  13.  
  14. IF LEN(runit$) THEN GetFileList runit$, Dir(), File() ELSE GetFileList _CWD$, Dir(), File()
  15. REDIM All(UBOUND(dir) - 1 + UBOUND(file)) AS STRING
  16.  
  17. i = 0
  18.  
  19.  
  20. FOR AllLoader = LBOUND(dir) + 2 TO UBOUND(dir) '                     i need not "." in list
  21.     IF LEN(Dir(AllLoader)) THEN All(i) = Dir(AllLoader): i = i + 1
  22. FOR AllLoader = LBOUND(file) TO UBOUND(file)
  23.     IF LEN(File(AllLoader)) THEN All(i) = File(AllLoader): i = i + 1
  24.  
  25.  
  26.  
  27.  
  28. DIRcount = UBOUND(dir) - 1
  29. FILEcount = UBOUND(file)
  30.  
  31.  
  32.     CLS
  33.     runit$ = Browse$(All(), 10, 10, 20, 10, DIRcount) 'array  contains files/directories names, this list X start coordinate, this list Y start coordinate, This list lenght (300 pixel lenght), 30 records in this list to view), return file/folder/"..", "." name which is selected
  34.     IF runit$ = "---E" THEN END
  35.     IF RIGHT$(runit$, 5) = ".DIR." THEN
  36.         runit$ = LEFT$(runit$, LEN(runit$) - 5)
  37.         CHDIR runit$: GOTO start
  38.     END IF
  39.     IF RIGHT$(runit$, 2) = ".." THEN CHDIR "..": GOTO start
  40.     SHELL _DONTWAIT runit$
  41.  
  42.  
  43.  
  44. FUNCTION Browse$ (arr() AS STRING, X, Y, lenght, height, numDirs)
  45.     ListColor& = _RGB32(166, 244, 244)
  46.     InPosColor& = _RGB32(67, 72, 238)
  47.     DirColor& = _RGB32(238, 22, 28)
  48.     Lb = 1
  49.     Le = 20
  50.     IF INSTR(1, _OS$, "WINDOWS") THEN sel$ = CHR$(92)
  51.     IF INSTR(1, _OS$, "LINUX") THEN sel$ = "/"
  52.     First = 1
  53.     DO
  54.         K& = _KEYHIT
  55.         oldposx = posx
  56.         IF First THEN oldposx = -1: First = 0
  57.         SELECT CASE K&
  58.             CASE 18432: posx = posx - 1: GU = 1: GD = 0 'marks: Go down disabled, go up enbabled
  59.             CASE 20480: posx = posx + 1: GU = 0: GD = 1 'marks: Go down enabled, go up disabled
  60.             CASE 13: Browse$ = _CWD$ + sel$ + arr(posx) + dd$: EXIT FUNCTION 'or if your choice is array record number then return PosX and erase $ in func name 'directory move is solved in my loop
  61.             CASE 27: Browse$ = "---E": EXIT FUNCTION
  62.         END SELECT
  63.         IF posx <= 0 THEN posx = 0: Lb = 0
  64.         IF posx > UBOUND(arr) - 1 THEN posx = UBOUND(arr) - 1
  65.         IF oldposx <> posx THEN
  66.             IF posx > height AND GD THEN Lb = Lb + 1: Le = Le + 1
  67.             IF GU AND Lb > 0 THEN Lb = Lb - 1: Le = Le - 1
  68.  
  69.             textpos = 0
  70.             IF Le > UBOUND(arr) THEN Le = UBOUND(arr)
  71.             IF Le - Lb > height THEN Le = Lb + height
  72.             FOR V = Lb TO Le 'List Begin to List End
  73.                 textpos = textpos + 20 'row is 20 pixel height
  74.                 IF V = posx THEN
  75.                     COLOR InPosColor&, ListColor&
  76.                 ELSE
  77.                     IF V > numDirs - 1 THEN COLOR ListColor& ELSE COLOR DirColor&
  78.                     IF posx <= numDirs - 1 THEN dd$ = ".DIR." ELSE dd$ = ""
  79.                 END IF
  80.  
  81.                 text$ = arr(V)
  82.                 IF LEN(text$) > lenght THEN text$ = LEFT$(text$, lenght - 3) + "..." ELSE text$ = text$ + SPACE$(lenght - LEN(text$))
  83.                 _PRINTSTRING (X, textpos), text$
  84.                 COLOR ListColor&, _RGB32(0, 0, 0)
  85.             NEXT V
  86.  
  87.         END IF
  88.     LOOP
  89.  
  90. SUB GetFileList (SearchDirectory AS STRING, DirList() AS STRING, FileList() AS STRING)
  91.     CONST IS_DIR = 1
  92.     CONST IS_FILE = 2
  93.     DIM flags AS LONG, file_size AS LONG
  94.  
  95.     REDIM _PRESERVE DirList(100), FileList(100)
  96.     DirCount = 0: FileCount = 0
  97.  
  98.     IF load_dir(SearchDirectory) THEN
  99.         DO
  100.             length = has_next_entry
  101.             IF length > -1 THEN
  102.                 nam$ = SPACE$(length)
  103.                 get_next_entry nam$, flags, file_size
  104.                 IF flags AND IS_DIR THEN
  105.                     DirCount = DirCount + 1
  106.                     IF DirCount > UBOUND(DirList) THEN REDIM _PRESERVE DirList(UBOUND(DirList) + 100)
  107.                     DirList(DirCount) = nam$
  108.                 ELSEIF flags AND IS_FILE THEN
  109.                     FileCount = FileCount + 1
  110.                     IF FileCount > UBOUND(filelist) THEN REDIM _PRESERVE FileList(UBOUND(filelist) + 100)
  111.                     FileList(FileCount) = nam$
  112.                 END IF
  113.             END IF
  114.         LOOP UNTIL length = -1
  115.         close_dir
  116.     ELSE
  117.     END IF
  118.     REDIM _PRESERVE DirList(DirCount)
  119.     REDIM _PRESERVE FileList(FileCount)
  120.  
* direntry.h (Filesize: 1.15 KB, Downloads: 267)

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Browsing Directories / files using Steve´s library
« Reply #1 on: July 08, 2018, 10:13:53 am »
Petr:  There is a way to get both folder information (which drives are available), and disk names, for both windows and Linux....   Problem is, I don't remember how I did it, right off the top of my head.  If you have a copy of my IDE which I was playing around with creating (StevesIDE), or my full fledged File Selection Utility (which I basically stripped from my IDE after working on it), then you can look inside either of them and see how I did it in the past.

If you don't have a copy of my IDE or FSU to examine, I'll dig up a version in a few days and refresh my memory on how I got all those things to work cross-platform.  I'd do it today for you, except my PC is in the shop having several internal fans and the power supply replaced.  I used to do such type repairs at home, but as I get old and my arthritis gets to hurting more, I find it simply easier and less stressful to leave such things to others anymore.

Give me 3-4 days to get my PC back, and if nobody has worked out a way by then, I'll dig out those old programs and see how I did it in the past again, for you.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Browsing Directories / files using Steve´s library
« Reply #2 on: July 08, 2018, 10:34:31 am »
Hi Steve, I'll look, but I do not have your files for 90 percent. It's a coincidence of coincidences, I'll just be for  daughter , now i waiting for a motherboard with processor and memory. About 3 months ago? I also left out the hard disk - he failure total,  so I got to know the UDF format I did not need before.  In old Computer my daughter ls wrong motherboard, there is a possibility of repair (it can be put into the oven and the temperature is kept under control for five minutes), it's due to lead-free tin, but ... I'd rather give her a new one.

Here I add the corrected previous program - I removed the sudden black death of the program. In the evening, I suppose I might be able to test it through Linux.

Code: QB64: [Select]
  1. 'files/directories list using Steve library (u.s. chars only)
  2. 'CHDIR "x:" tested on network drive, ok work correctly
  3.  
  4.  
  5.     FUNCTION load_dir& (s AS STRING)
  6.     FUNCTION has_next_entry& ()
  7.     SUB close_dir ()
  8.     SUB get_next_entry (s AS STRING, flags AS LONG, file_size AS LONG)
  9. SCREEN _NEWIMAGE(800, 600, 32)
  10.  
  11.  
  12. start:
  13.  
  14.  
  15. REDIM Dir(0) AS STRING, File(0) AS STRING
  16.  
  17. IF LEN(runit$) THEN GetFileList runit$, Dir(), File() ELSE GetFileList _CWD$, Dir(), File()
  18. REDIM All(UBOUND(dir) - 1 + UBOUND(file)) AS STRING
  19.  
  20. i = 0
  21.  
  22.  
  23. FOR AllLoader = LBOUND(dir) + 2 TO UBOUND(dir) '                     i need not "." in list
  24.     IF LEN(Dir(AllLoader)) THEN All(i) = Dir(AllLoader): i = i + 1
  25. FOR AllLoader = LBOUND(file) TO UBOUND(file)
  26.     IF LEN(File(AllLoader)) THEN All(i) = File(AllLoader): i = i + 1
  27.  
  28.  
  29.  
  30.  
  31. DIRcount = UBOUND(dir) - 1
  32. FILEcount = UBOUND(file)
  33. IF DIRcount < 0 THEN DIRcount = 0
  34.  
  35.     CLS
  36.     runit$ = Browse$(All(), 10, 10, 70, 15, DIRcount) 'array  contains files/directories names, this list X start coordinate, this list Y start coordinate, This list lenght (300 pixel lenght), 30 records in this list to view), return file/folder/"..", "." name which is selected
  37.     IF runit$ = "---E" THEN END
  38.     IF runit$ = "" THEN GOTO start
  39.     IF RIGHT$(runit$, 5) = ".DIR." THEN
  40.         runit$ = LEFT$(runit$, LEN(runit$) - 5)
  41.         CLS
  42.         REM    PRINT runit$: SLEEP
  43.         CHDIR runit$: GOTO start
  44.     END IF
  45.     IF RIGHT$(runit$, 2) = ".." THEN CHDIR "..": GOTO start
  46.     IF LEN(runit$) THEN SHELL _DONTWAIT runit$
  47.  
  48.  
  49.  
  50.  
  51. FUNCTION Browse$ (arr() AS STRING, X, Y, lenght, height, numDirs)
  52.     fail:
  53.     ListColor& = _RGB32(166, 244, 244)
  54.     InPosColor& = _RGB32(67, 72, 238)
  55.     DirColor& = _RGB32(238, 22, 28)
  56.     Lb = 1
  57.     Le = 20
  58.     IF INSTR(1, _OS$, "WINDOWS") THEN sel$ = CHR$(92)
  59.     IF INSTR(1, _OS$, "LINUX") THEN sel$ = "/"
  60.     First = 1
  61.     DO
  62.         K& = _KEYHIT
  63.         oldposx = posx
  64.         IF First THEN oldposx = -1: First = 0
  65.         SELECT CASE K&
  66.             CASE 18432: posx = posx - 1: GU = 1: GD = 0 'marks: Go down disabled, go up enbabled
  67.             CASE 20480: posx = posx + 1: GU = 0: GD = 1 'marks: Go down enabled, go up disabled
  68.             CASE 13: Browse$ = _CWD$ + sel$ + arr(posx) + dd$: EXIT FUNCTION 'or if your choice is array record number then return PosX and erase $ in func name 'directory move is solved in my loop
  69.             CASE 27: Browse$ = "---E": EXIT FUNCTION
  70.         END SELECT
  71.         IF posx <= 0 THEN posx = 0: Lb = 0
  72.         '        IF arr(posx) = "." THEN posx = 1: Lb = 1
  73.  
  74.         IF posx > UBOUND(arr) - 1 THEN posx = UBOUND(arr) - 1
  75.         IF oldposx <> posx THEN
  76.             IF posx > height AND GD THEN Lb = Lb + 1: Le = Le + 1
  77.             IF GU AND Lb > 0 THEN Lb = Lb - 1: Le = Le - 1
  78.  
  79.             textpos = 0
  80.             IF Le > UBOUND(arr) THEN Le = UBOUND(arr)
  81.             IF Le - Lb > height THEN Le = Lb + height
  82.             IF Lb > Le THEN EXIT SUB
  83.             FOR V = Lb TO Le 'List Begin to List End
  84.                 textpos = textpos + 20 'row is 20 pixel height
  85.                 IF V = posx THEN
  86.                     COLOR InPosColor&, ListColor&
  87.                 ELSE
  88.                     IF V > numDirs - 1 THEN COLOR ListColor& ELSE COLOR DirColor&
  89.                     IF posx <= numDirs - 1 THEN dd$ = ".DIR." ELSE dd$ = ""
  90.                 END IF
  91.  
  92.                 text$ = arr(V)
  93.                 IF LEN(text$) > lenght THEN text$ = LEFT$(text$, lenght - 3) + "..." ELSE text$ = text$ + SPACE$(lenght - LEN(text$))
  94.                 _PRINTSTRING (X, textpos), text$
  95.                 COLOR ListColor&, _RGB32(0, 0, 0)
  96.             NEXT V
  97.         END IF
  98.         _LIMIT 25
  99.     LOOP
  100.  
  101. SUB GetFileList (SearchDirectory AS STRING, DirList() AS STRING, FileList() AS STRING)
  102.     CONST IS_DIR = 1
  103.     CONST IS_FILE = 2
  104.     DIM flags AS LONG, file_size AS LONG
  105.  
  106.     REDIM _PRESERVE DirList(100), FileList(100)
  107.     DirCount = 0: FileCount = 0
  108.  
  109.     IF load_dir(SearchDirectory) THEN
  110.         DO
  111.             length = has_next_entry
  112.             IF length > -1 THEN
  113.                 nam$ = SPACE$(length)
  114.                 get_next_entry nam$, flags, file_size
  115.                 IF flags AND IS_DIR THEN
  116.                     DirCount = DirCount + 1
  117.                     IF DirCount > UBOUND(DirList) THEN REDIM _PRESERVE DirList(UBOUND(DirList) + 100)
  118.                     DirList(DirCount) = nam$
  119.                 ELSEIF flags AND IS_FILE THEN
  120.                     FileCount = FileCount + 1
  121.                     IF FileCount > UBOUND(filelist) THEN REDIM _PRESERVE FileList(UBOUND(filelist) + 100)
  122.                     FileList(FileCount) = nam$
  123.                 END IF
  124.             END IF
  125.         LOOP UNTIL length = -1
  126.         close_dir
  127.     ELSE
  128.     END IF
  129.     REDIM _PRESERVE DirList(DirCount)
  130.     REDIM _PRESERVE FileList(FileCount)
  131.  
  132.  

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Browsing Directories / files using Steve´s library
« Reply #3 on: July 08, 2018, 07:07:18 pm »
See if this is what you're looking for Petr:

Code: QB64: [Select]
  1.     FUNCTION FILE_load_dir& ALIAS load_dir (s AS STRING)
  2.     FUNCTION FILE_has_next_entry& ALIAS has_next_entry ()
  3.     SUB FILE_close_dir ALIAS close_dir ()
  4.     SUB FILE_get_next_entry ALIAS get_next_entry (s AS STRING, flags AS LONG, file_size AS LONG)
  5.     SUB FILE_get_current_dir ALIAS get_current_dir (s AS STRING)
  6.     FUNCTION FILE_current_dir_length& ALIAS current_dir_length ()
  7.  
  8.  
  9. SCREEN _NEWIMAGE(800, 600, 32)
  10. f$ = SelectFile$("*.BI;*.BAS;*.BM;*.*", 60, 60)
  11. PRINT "You picked "; f$
  12.  
  13.  
  14.  
  15.  
  16. FUNCTION SelectFile$ (search$, x AS INTEGER, y AS INTEGER)
  17.     'save some old values
  18.     LoadFile_DC = _DEFAULTCOLOR: LoadFile_BG = _BACKGROUNDCOLOR
  19.     LoadFile_s = _SOURCE: LoadFile_d = _DEST
  20.     f = _FONT: _FONT 16
  21.     'some variables
  22.  
  23.     LoadFile_BoxColor = &HFFAAAAFF
  24.     LoadFile_FolderColor = &HFFFFFF00
  25.     LoadFile_FileColor = &HFFFFFFFF
  26.     IF INSTR(_OS$, "[WINDOWS]") THEN LoadFile_Slash$ = "\" ELSE LoadFile_Slash$ = "/"
  27.     LoadFile_Dir$ = SPACE$(FILE_current_dir_length)
  28.     FILE_get_current_dir LoadFile_Dir$
  29.     LoadFile_Dir$ = LoadFile_Dir$ + LoadFile_Slash$
  30.     LoadFile_w = 639: LoadFile_h = 479
  31.     REDIM LoadFile_Label(0) AS STRING: LoadFile_Label(0) = "DIR"
  32.     REDIM LoadFile_DirList(-1 TO 9, -1 TO 9999) AS STRING
  33.     LoadFile_last = 1
  34.     REDIM Drives(0) AS STRING
  35.  
  36.     'some error checking
  37.     IF search$ = "" THEN EXIT SUB 'We can't search for nothing!
  38.  
  39.     'Copy background
  40.     PCOPY 0, 1
  41.     'set workscreen
  42.     LoadFile_ws = _NEWIMAGE(640, 480, 32)
  43.  
  44.     'Count our filetypes to display
  45.     LoadFile_TypeCount = 0
  46.     DO
  47.         LoadFile_TypeCount = LoadFile_TypeCount + 1
  48.         LoadFile_l = INSTR(LoadFile_l + 1, search$, ";") ' look for ; to denote more files
  49.         REDIM _PRESERVE LoadFile_Label(LoadFile_TypeCount) AS STRING
  50.         IF LoadFile_l > 0 THEN LoadFile_Label(LoadFile_TypeCount) = MID$(search$, LoadFile_last + 1, LoadFile_l - LoadFile_last - 1) ELSE LoadFile_Label(LoadFile_TypeCount) = MID$(search$, LoadFile_last + 1, LEN(search$) - LoadFile_last)
  51.         LoadFile_last = LoadFile_l + 1
  52.     LOOP UNTIL LoadFile_l = 0
  53.     LoadFile_l = 640 / (LoadFile_TypeCount + 1)
  54.     REDIM LoadFile_start(LoadFile_TypeCount), LoadFile_previous(LoadFile_TypeCount), LoadFile_more(LoadFile_TypeCount), LoadFile_Count(LoadFile_TypeCount)
  55.     FOR i = 0 TO LoadFile_TypeCount: LoadFile_start(i) = 1: NEXT
  56.  
  57.     'Get the windows drive letters
  58.     IF INSTR(_OS$, "[WINDOWS]") THEN
  59.         SHELL _HIDE CHR$(34) + "wmic logicaldisk get name" + CHR$(34) + ">TempDirList.txt"
  60.         REDIM Drives(0) AS STRING
  61.  
  62.         OPEN "TempDirList.txt" FOR INPUT AS #1
  63.         LINE INPUT #1, junk$ 'First line is  name
  64.         counter = 0
  65.         DO UNTIL EOF(1)
  66.             counter = counter + 1
  67.             INPUT #1, junk$ 'drive name
  68.             REDIM _PRESERVE Drives(counter) AS STRING
  69.             IF LEN(junk$) > 1 THEN junk$ = MID$(junk$, 2, 1) + ":" ELSE junk$ = "": counter = counter - 1
  70.             IF junk$ <> "" THEN
  71.                 Drives(counter) = junk$
  72.             END IF
  73.         LOOP
  74.         CLOSE #1
  75.         KILL "TempDirList.txt"
  76.     END IF
  77.  
  78.  
  79.     _SOURCE LoadFile_ws: _DEST LoadFile_ws
  80.     DO
  81.  
  82.         FOR i = 0 TO LoadFile_TypeCount
  83.             LoadFile_Count(i) = 0
  84.             FOR j = 0 TO 9999
  85.                 LoadFile_DirList(i, j) = ""
  86.             NEXT
  87.         NEXT
  88.         'Generate our updated directory listings.
  89.  
  90.         IF FILE_load_dir&(LoadFile_Dir$ + CHR$(0)) THEN
  91.             DO
  92.                 LoadFile_length = FILE_has_next_entry 'Get length of next entry
  93.                 IF LoadFile_length > -1 THEN 'If we have a next entry
  94.                     LoadFile_nam$ = SPACE$(LoadFile_length) 'Set the size of our string
  95.                     FILE_get_next_entry LoadFile_nam$, LoadFile_flags, LoadFile_file_size 'Get the file's name, size, and 'flags'
  96.                     'Check if it's a file or a directory
  97.  
  98.                     IF _DIREXISTS(LoadFile_Dir$ + LoadFile_nam$) THEN
  99.                         IF LoadFile_nam$ <> "." THEN
  100.                             LoadFile_Count(0) = LoadFile_Count(0) + 1
  101.                             LoadFile_DirList(0, LoadFile_Count(0)) = LoadFile_nam$
  102.                         END IF
  103.                     ELSE 'We have a file
  104.                         FOR i = 1 TO LoadFile_TypeCount
  105.                             LoadFile_ext$ = RIGHT$(LoadFile_nam$, LEN(LoadFile_Label(i)))
  106.                             IF UCASE$(LoadFile_ext$) = UCASE$(LoadFile_Label(i)) THEN
  107.                                 LoadFile_Count(i) = LoadFile_Count(i) + 1
  108.                                 LoadFile_DirList(i, LoadFile_Count(i)) = LEFT$(LoadFile_nam$, LEN(LoadFile_nam$) - LEN(LoadFile_Label(i)))
  109.                                 EXIT FOR
  110.                             ELSEIF LoadFile_Label(i) = ".*" THEN
  111.                                 LoadFile_Count(i) = LoadFile_Count(i) + 1
  112.                                 LoadFile_DirList(i, LoadFile_Count(i)) = LoadFile_nam$
  113.                             END IF
  114.                         NEXT
  115.                     END IF
  116.                 END IF
  117.             LOOP UNTIL LoadFile_length = -1
  118.             FILE_close_dir
  119.         END IF
  120.  
  121.         FOR i = 1 TO UBOUND(drives)
  122.             LoadFile_Count(0) = LoadFile_Count(0) + 1
  123.             LoadFile_DirList(0, LoadFile_Count(0)) = Drives(i)
  124.         NEXT
  125.  
  126.         updatelist:
  127.  
  128.         CLS , &HFF005050 'Draw a nice display box
  129.         COLOR , 0
  130.         LINE (0, 0)-(LoadFile_w, LoadFile_h + 5 - 2 * 16), LoadFile_BoxColor, B
  131.         LINE (1, 1)-(LoadFile_w - 1, LoadFile_h + 6 - 2 * 16), LoadFile_BoxColor, B
  132.         LINE (0, 0)-(LoadFile_w, LoadFile_h), LoadFile_BoxColor, B
  133.         LINE (1, 1)-(LoadFile_w - 1, LoadFile_h - 1), LoadFile_BoxColor, B
  134.  
  135.         LINE (0, 16 + 3)-(LoadFile_w, 16 + 3), LoadFile_BoxColor
  136.         LINE (0, 16 + 4)-(LoadFile_w, 16 + 4), LoadFile_BoxColor
  137.         FOR i = 0 TO LoadFile_TypeCount
  138.             _PRINTSTRING (i * LoadFile_l + (LoadFile_l - 8 * LEN(LoadFile_Label(i))) / 2, 2), LoadFile_Label(i)
  139.             LINE (i * LoadFile_l, 0)-(i * LoadFile_l, LoadFile_h + 5 - 2 * 16), LoadFile_BoxColor
  140.         NEXT
  141.  
  142.         LINE (627, 2)-(637, 18), &HFFFF0000, BF
  143.         LINE (626, 2)-(637, 18), &HFF000000, B
  144.  
  145.         _PRINTSTRING (628, 2), "X"
  146.         IF selection > 0 THEN
  147.             IF LoadFile_Label(row) <> ".*" AND LoadFile_Label(row) <> "DIR" THEN temp$ = LoadFile_DirList(row, selection) + LoadFile_Label(row) ELSE temp$ = LoadFile_DirList(row, selection)
  148.             IF LoadFile_DirList(row, selection) = "" THEN temp$ = ""
  149.             selection = 0
  150.         END IF
  151.         _PRINTSTRING (10, 28 * 16 + 7), LoadFile_Dir$
  152.         _PRINTSTRING (630 - LEN(temp$) * 8, 28 * 16 + 7), temp$
  153.         IF temp$ = "" THEN oldselection = 0
  154.         IF oldselection > 0 THEN LINE (row * LoadFile_l, (oldselection + 1) * 16 + 5)-((row + 1) * LoadFile_l, (oldselection + 2) * 16 + 5), &HAAAAA000, BF
  155.  
  156.         FOR i = 0 TO UBOUND(LoadFile_label)
  157.             IF i = 0 THEN COLOR LoadFile_FolderColor ELSE COLOR LoadFile_FileColor
  158.             counter = 0
  159.             FOR j = LoadFile_start(i) TO LoadFile_start(i) + 24
  160.                 counter = counter + 1
  161.                 IF LoadFile_DirList(i, j) = "" THEN EXIT FOR
  162.                 _PRINTSTRING (i * LoadFile_l + 5, (counter + 1) * 16 + 7), LEFT$(LoadFile_DirList(i, j), LoadFile_l / 8 - 2)
  163.             NEXT
  164.             IF j = LoadFile_start(i) + 25 THEN LoadFile_more(i) = -1 ELSE LoadFile_more(i) = 0
  165.             IF LoadFile_start(i) > 1 THEN LoadFile_previous(i) = -1 ELSE LoadFile_previous(i) = 0
  166.             IF LoadFile_more(i) THEN
  167.                 LINE (i * LoadFile_l + 2, 27 * 16 + 5)-((i + 1) * LoadFile_l - 3, 28 * 16 + 3), &HFFFF0000, BF
  168.                 LINE (i * LoadFile_l + 2, 27 * 16 + 5)-((i + 1) * LoadFile_l - 3, 28 * 16 + 3), BoxColor, B
  169.                 COLOR &HFFFFFF00: _PRINTSTRING (i * LoadFile_l + (LoadFile_l - 8 * 11) / 2, 27 * 16 + 5), "SCROLL DOWN"
  170.                 COLOR LoadFile_FileColor
  171.             END IF
  172.             IF LoadFile_previous(i) THEN
  173.                 LINE (i * LoadFile_l + 2, 16 + 5)-((i + 1) * LoadFile_l - 3, 2 * 16 + 3), &HFFFF0000, BF
  174.                 LINE (i * LoadFile_l + 2, 16 + 5)-((i + 1) * LoadFile_l - 3, 2 * 16 + 3), BoxColor, B
  175.                 COLOR &HFFFFFF00: _PRINTSTRING (i * LoadFile_l + (LoadFile_l - 8 * 9) / 2, 16 + 5), "SCROLL UP"
  176.                 COLOR LoadFile_FileColor
  177.             END IF
  178.         NEXT
  179.  
  180.         _PUTIMAGE (0 + x, 0 + y)-(640 + x, 480 + y), LoadFile_ws, 0
  181.         _DISPLAY
  182.  
  183.         change = 0
  184.         DO
  185.             _DELAY .05
  186.             LoadFile_LMB = 0 'This sets the left mouse button as unacceptable.
  187.             a = _KEYHIT
  188.             SELECT CASE a
  189.                 CASE 8 'backspace
  190.                     temp$ = LEFT$(temp$, LEN(temp$) - 1)
  191.                     change = -1
  192.                 CASE 13 'enter
  193.                     DO: LOOP UNTIL INKEY$ = "" 'Clear the keyboard buffer so it doesn't affect the main program.
  194.                     temp$ = LoadFile_Dir$ + temp$
  195.                     COLOR LoadFile_DC, LoadFile_BG: _SOURCE LoadFile_s: _DEST LoadFile_d: PCOPY 1, 0: _DISPLAY: SelectFile$ = temp$ 'Restore our old settings
  196.                     _FONT f
  197.                     EXIT SUB 'And leave
  198.                 CASE 27 'If ESC is pressed then...
  199.                     DO: LOOP UNTIL INKEY$ = "" 'Clear the keyboard buffer so it doesn't affect the main program.
  200.                     COLOR LoadFile_DC, LoadFile_BG: _SOURCE LoadFile_s: _DEST LoadFile_d: PCOPY 1, 0: _DISPLAY: SelectFile$ = "" 'Restore our old settings
  201.                     _FONT f
  202.                     EXIT SUB 'And leave
  203.                 CASE 32 TO 126
  204.                     temp$ = temp$ + CHR$(a)
  205.                     change = -1
  206.             END SELECT
  207.             DO
  208.                 MS = MS + _MOUSEWHEEL
  209.                 IF _MOUSEBUTTON(1) = 0 THEN LoadFile_LMB = -1 'Only by lifting the mouse, will we count it as down
  210.                 'Note: we ignore LoadFile_LMB for the scroll bars, so we can just hold it down and scroll happily forever and ever...
  211.                 'or until we get to the limit of our file list.
  212.                 'We only check LoadFile_LMB when actually trying to select an item from our list.   No more "OOP!  I held it too long and did something I didn't want to do!"
  213.                 'Now we click once to select, click again to accept that selection.
  214.             LOOP WHILE _MOUSEINPUT
  215.             MX = _MOUSEX: MY = _MOUSEY
  216.             IF _MOUSEBUTTON(2) OR (LoadFile_LMB AND MX > 626 + x AND MX < 638 + x AND MY > 1 + y AND MY < 19 + y AND _MOUSEBUTTON(1)) THEN
  217.                 'restore those old values, and just exit.  Right mouse is an escape
  218.                 COLOR LoadFile_DC, LoadFile_BG: _SOURCE LoadFile_s: _DEST LoadFile_d: PCOPY 1, 0: _DISPLAY: SelectFile$ = ""
  219.                 _FONT f
  220.                 EXIT SUB
  221.             END IF
  222.  
  223.  
  224.  
  225.  
  226.  
  227.             IF _MOUSEBUTTON(1) THEN 'Without the mouse being down, we don't need to check squat!
  228.                 'Check the 2 roLoadFile_ws for a click in the proper Y position
  229.                 IF MY >= 16 + 5 + y AND MY <= 2 * 16 + 3 + y THEN 'We're on the top row
  230.                     FOR j = 0 TO UBOUND(LoadFile_label)
  231.                         IF LoadFile_previous(j) AND MX >= j * LoadFile_l + 2 + x AND MX <= (j + 1) * LoadFile_l - 3 + x THEN
  232.                             LoadFile_start(j) = LoadFile_start(j) - 1
  233.                             change = -1: selection = 0: click = 0: temp$ = ""
  234.                             EXIT FOR
  235.                         END IF
  236.                     NEXT
  237.                 ELSEIF MY >= 27 * 16 + 5 + y AND MY <= 28 * 16 + 3 + y THEN 'We're on the bottom row
  238.                     FOR j = 0 TO UBOUND(LoadFile_label)
  239.                         IF LoadFile_more(j) AND MX >= j * LoadFile_l + 2 + x AND MX <= (j + 1) * LoadFile_l - 3 + x THEN
  240.                             LoadFile_start(j) = LoadFile_start(j) + 1
  241.                             change = -1: selection = 0: click = 0: temp$ = ""
  242.                             EXIT FOR
  243.                         END IF
  244.                     NEXT
  245.                 ELSEIF MY >= 37 + y AND MY <= 437 + y AND LoadFile_LMB THEN 'It's in a column somewhere.  Did someone click an item?!
  246.                     FOR j = 0 TO UBOUND(LoadFile_label)
  247.                         IF MX >= j * LoadFile_l + 2 + x AND MX <= (j + 1) * LoadFile_l - 3 + x THEN
  248.                             row = j
  249.                             oldselection = INT((MY - y - 37) / 16) + 1
  250.                             selection = LoadFile_start(j) + oldselection - 1
  251.                             change = -1
  252.                             click = -1
  253.                             EXIT FOR
  254.                         END IF
  255.                     NEXT
  256.                 END IF
  257.             END IF
  258.             IF MS <> 0 THEN
  259.                 IF MY >= 37 + y AND MY <= 437 + y AND LoadFile_LMB THEN 'It's in a column somewhere.  Did someone click an item?!
  260.                     FOR j = 0 TO UBOUND(LoadFile_label)
  261.                         IF MX >= j * LoadFile_l + 2 + x AND MX <= (j + 1) * LoadFile_l - 3 + x THEN
  262.                             IF LoadFile_previous(j) AND MS < 1 THEN
  263.                                 LoadFile_start(j) = LoadFile_start(j) - 5
  264.                                 IF LoadFile_start(j) < 1 THEN LoadFile_start(j) = 1
  265.                                 change = -1: selection = 0: click = 0: temp$ = ""
  266.                                 MS = 0
  267.                             ELSEIF LoadFile_more(j) AND MS > 1 THEN
  268.                                 LoadFile_start(j) = LoadFile_start(j) + 5
  269.                                 change = -1: selection = 0: click = 0: temp$ = ""
  270.                                 MS = 0
  271.                             END IF
  272.                             EXIT FOR
  273.                         END IF
  274.                     NEXT
  275.                 ELSE MS = 0
  276.                 END IF
  277.             END IF
  278.             _DISPLAY
  279.         LOOP UNTIL change
  280.         IF click THEN 'we clicked something besides a scroll bar
  281.             IF LoadFile_Label(row) <> ".*" AND LoadFile_Label(row) <> "DIR" THEN temp1$ = LoadFile_DirList(row, selection) + LoadFile_Label(row) ELSE temp1$ = LoadFile_DirList(row, selection)
  282.             IF temp$ = temp1$ THEN
  283.                 'We picked one!
  284.                 SELECT CASE LoadFile_Label(row)
  285.                     CASE "DIR"
  286.                         SELECT CASE LoadFile_DirList(row, selection)
  287.                             CASE "" 'Do nothing with blank directories
  288.                             CASE ".." 'Up a folder
  289.                                 DO
  290.                                     LoadFile_Dir$ = LEFT$(LoadFile_Dir$, LEN(LoadFile_Dir$) - 1)
  291.                                 LOOP UNTIL RIGHT$(LoadFile_Dir$, 1) = LoadFile_Slash$ OR LEN(LoadFile_Dir$) = 0
  292.                             CASE ELSE 'To a specific folder
  293.                                 IF LEN(LoadFile_DirList(row, selection)) = 2 AND RIGHT$(LoadFile_DirList(row, selection), 1) = ":" THEN
  294.                                     'It's a directory change
  295.                                     LoadFile_Dir$ = LoadFile_DirList(row, selection) + LoadFile_Slash$
  296.                                 ELSE
  297.                                     LoadFile_Dir$ = LoadFile_Dir$ + LoadFile_DirList(row, selection) + LoadFile_Slash$
  298.                                 END IF
  299.                         END SELECT
  300.                         FOR i = 0 TO UBOUND(Loadfile_start)
  301.                             LoadFile_start(i) = 1
  302.                         NEXT
  303.                         selection = 0: temp$ = "": oldselection = 0
  304.                     CASE ".*": SelectFile$ = LoadFile_Dir$ + temp$: EXIT DO
  305.                     CASE ELSE: SelectFile$ = LoadFile_Dir$ + temp$: EXIT DO
  306.                 END SELECT
  307.             END IF
  308.             IF row > 0 THEN _DELAY .2: GOTO updatelist
  309.         ELSE
  310.             _DELAY .05
  311.             GOTO updatelist
  312.         END IF
  313.     LOOP
  314.     'restore those old values
  315.     COLOR LoadFile_DC, LoadFile_BG: _SOURCE LoadFile_s: _DEST LoadFile_d: PCOPY 1, 0: _DISPLAY
  316.     _FONT f
  317.  
  318. 'If you don't have a copy of direntry.h in your QB64 folder, then copy the following code into a new IDE window.
  319. 'Then remove the remarks.
  320. 'And save it as direntry.h
  321. 'direntry.h is required for this to work properly with the library files.
  322. 'I thought adding the code here would be a way to make certain that it'd be easy to recover the file
  323. 'in case something ever happened and it was accidently deleted off the drive for some reason.
  324.  
  325. '#include <dirent.h>
  326. '#include <sys/stat.h>
  327. '#include <unistd.h>
  328.  
  329. 'const int IS_DIR_FLAG = 1, IS_FILE_FLAG = 2;
  330.  
  331. 'DIR *pdir;
  332. 'struct dirent *next_entry;
  333. 'struct stat statbuf1;
  334.  
  335. 'char current_dir[FILENAME_MAX];
  336. '#ifdef QB64_WINDOWS
  337. '  #define GetCurrentDir _getcwd
  338. '#else
  339. '  #define GetCurrentDir getcwd
  340. '#endif
  341.  
  342. 'int load_dir (char * path) {
  343. '  struct dirent *pent;
  344. '  struct stat statbuf1;
  345. '//Open current directory
  346. 'pdir = opendir(path);
  347. 'if (!pdir) {
  348. 'return 0; //Didn't open
  349. '}
  350. 'return -1;
  351. '}
  352.  
  353. 'int has_next_entry () {
  354. '  next_entry = readdir(pdir);
  355. '  if (next_entry == NULL) return -1;
  356.  
  357. '  stat(next_entry->d_name, &statbuf1);
  358. '  return strlen(next_entry->d_name);
  359. '}
  360.  
  361. 'void get_next_entry (char * nam, int * flags, int * file_size) {
  362. '  strcpy(nam, next_entry->d_name);
  363. '  if (S_ISDIR(statbuf1.st_mode)) {
  364. '    *flags = IS_DIR_FLAG;
  365. '  } else {
  366. '    *flags = IS_FILE_FLAG;
  367. '  }
  368. '  *file_size = statbuf1.st_size;
  369. '  return ;
  370. '}
  371.  
  372. 'void close_dir () {
  373. '  closedir(pdir);
  374. '  pdir = NULL;
  375. '  return ;
  376. '}
  377.  
  378. 'int current_dir_length () {
  379. '  GetCurrentDir(current_dir, sizeof(current_dir));
  380. '  return strlen(current_dir);
  381. '}
  382.  
  383. 'void get_current_dir(char *dir) {
  384. '  memcpy(dir, current_dir, strlen(current_dir));
  385. '  return ;
  386. '}
  387.  

Just be certain to have the direntry.h file where it can be found, and you should be good to go.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Browsing Directories / files using Steve´s library
« Reply #4 on: July 09, 2018, 10:54:32 am »
Hi Steve. Yes, it is, thank you. Does the disk listing appear to be only for windows? (I will study the linux commands sequentially if there is not the same option). Thank you very much for your idea and source!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Browsing Directories / files using Steve´s library
« Reply #5 on: July 09, 2018, 02:25:39 pm »
Hi Steve. Yes, it is, thank you. Does the disk listing appear to be only for windows? (I will study the linux commands sequentially if there is not the same option). Thank you very much for your idea and source!

Linux and Windows are inherently different in the way they handle their file system.  Take a quick read here:  https://www.howtogeek.com/137096/6-ways-the-linux-file-system-is-different-from-the-windows-file-system/

The particular point of interest for you, in this case, would be:

No Drive Letters – It’s All Under /

Windows exposes partitions and devices at drive letters. Whether you have multiple hard drives, multiple partitions on the same hard drive, or removable devices connected, each file system is available under its own drive letter.

Linux doesn’t have drive letters. Instead, it makes other file systems accessible at arbitrary directories. (Windows can do this too, but this isn’t how it works out of the box.)

On Linux, everything is under / – the root directory. There are no files above the root directory, as there are files outside of C: on Windows. When you connect a device to your computer, it will become available under /media/. The contents of the directory display the contents of the mounted partition.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Browsing Directories / files using Steve´s library
« Reply #6 on: July 09, 2018, 04:11:44 pm »
Thank you for the explanation. After several attempts (DVD ROM after death,too small FlashDisc, fragmented harddrive....), I finally i got to computer Linux Mint. I will experimented.

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: Browsing Directories / files using Steve´s library
« Reply #7 on: July 10, 2018, 11:16:54 am »
Wow, amazing work Petr and Steve. I think these dir listing routines along with Steve's circle fill are the two most prolific code snippets in QB64. Really speaks for Steve's immensity.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Browsing Directories / files using Steve´s library
« Reply #8 on: July 10, 2018, 12:41:42 pm »
Thank you, V, I'm still improving function Browse$.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Browsing Directories / files using Steve´s library
« Reply #9 on: August 13, 2018, 04:54:48 pm »
This is my latest version, so far it does not support GOOD mouse drives switching (support files / directories move by clicking to arrow ) but can be switched by keyboard (just press character). I still need to make an alphabetical order for linux. Here I have a problem. What should be first. Small or big character? I did not try it in Linux, I'm a little while after vacation. In the windows, I've been having problems with links that have returned as directories or directories that are not directly accessible. I will use this program for Sprite editor, which I promised Johnno56.


Code: QB64: [Select]
  1. 'files/directories list using Steve library (u.s. chars only)
  2. 'CHDIR "x:" tested on network drive, ok work correctly
  3.  
  4. REDIM Drives(0) AS STRING
  5.     FUNCTION load_dir& (s AS STRING)
  6.     FUNCTION has_next_entry& ()
  7.     SUB close_dir ()
  8.     SUB get_next_entry (s AS STRING, flags AS LONG, file_size AS LONG)
  9.  
  10. SCREEN _NEWIMAGE(800, 600, 32)
  11.  
  12.  
  13. Drives$ = LoadDrives$(Drives()) 'windows only in current version
  14.  
  15.  
  16. REDIM DirNew(0) AS STRING
  17. REDIM FileNew(0) AS STRING
  18.  
  19. start:
  20.  
  21.  
  22. REDIM Dir(0) AS STRING, File(0) AS STRING
  23.  
  24.  
  25. GetFileList _CWD$, Dir(), File()
  26. REDIM All(UBOUND(dir) - 1 + UBOUND(file)) AS STRING
  27.  
  28. i = 0
  29.  
  30.  
  31. FOR AllLoader = LBOUND(dir) + 2 TO UBOUND(dir) '                     i need not "." in list
  32.     IF LEN(Dir(AllLoader)) THEN All(i) = Dir(AllLoader): i = i + 1
  33. FOR AllLoader = LBOUND(File) TO UBOUND(File)
  34.     IF LEN(File(AllLoader)) THEN All(i) = File(AllLoader): i = i + 1
  35.  
  36. IF UBOUND(all) <= 0 THEN CHDIR (LEFT$(_CWD$, 3)): GOTO start
  37.  
  38. DIRcount = UBOUND(dir) - 1
  39. FILEcount = UBOUND(File)
  40. IF DIRcount < 0 THEN DIRcount = 0
  41. IF INSTR(1, _OS$, "WINDOWS") THEN OS = 0
  42. IF INSTR(1, _OS$, "LINUX") THEN OS = 1
  43.  
  44.     CLS
  45.     runit$ = ""
  46.     runit$ = Browse$(All(), 20, 15, 40, 9, DIRcount, Drives$, 1) 'array  contains files/directories names, this list X start coordinate, this list Y start coordinate, This list lenght (300 pixel lenght), 30 records in this list to view), return file/folder/"..", "." name which is selected. Last parameter is for DRIVE characters (names) STRING
  47.     '    PRINT runit$: SLEEP 2
  48.     ON ERROR GOTO handler
  49.  
  50.  
  51.     SELECT CASE OS
  52.         CASE 0
  53.             invalid = INSTR(1, runit$, "\\")
  54.         CASE 1
  55.             invalid = INSTR(1, runit$, "//")
  56.     END SELECT
  57.     IF invalid THEN runit$ = LEFT$(runit$, invalid) + RIGHT$(runit$, LEN(runit$) - invalid - 1)
  58.  
  59.  
  60.     IF RIGHT$(runit$, 1) = "." AND OS = 1 THEN BEEP: CHDIR "/": _DELAY .1: GOTO start
  61.  
  62.  
  63.  
  64.     IF runit$ = "---E" THEN END
  65.     IF runit$ = "" THEN CHDIR LEFT$(_CWD$, 3): _DELAY .1: GOTO start
  66.     IF RIGHT$(runit$, 2) = ".." AND _DIREXISTS("..") THEN CHDIR "..": _DELAY .1: GOTO start
  67.     IF RIGHT$(runit$, 5) = ".DIR." THEN
  68.         runit$ = LEFT$(runit$, LEN(runit$) - 5)
  69.         CHDIR runit$
  70.         _DELAY .1
  71.         GOTO start
  72.     END IF
  73.  
  74.     IF LEN(runit$) AND _FILEEXISTS(runit$) THEN SHELL _DONTWAIT runit$
  75.  
  76.  
  77. handler:
  78.  
  79. PRINT "error handler RUN!!!!": SLEEP 2
  80.     CASE 76: CHDIR LEFT$(_CWD$, 3) + ":": GOTO start: RESUME NEXT 'path not found ugrade / add + ":" and goto start
  81.  
  82.  
  83.  
  84. FUNCTION Browse$ (arr() AS STRING, X, Y, lenght, height, numDirs, Drives AS STRING, UseWheel)
  85.     ' X and Y are coordinates for left upper corner, lenght is window lenght in CHARACTERS, height is window height in records + 2, numDirs = how nmuch
  86.     ' records from begin in array arr() are DIRECTORIES, Drives is string contains valid disk names in Windows, in Linux it is empty string
  87.  
  88.     ListColor& = _RGB32(166, 244, 244)
  89.     InPosColor& = _RGB32(67, 72, 238)
  90.     DirColor& = _RGB32(238, 22, 28)
  91.     'create string with drives names (i see this first by Eoredson)
  92.     FOR Driv = 1 TO LEN(Drives)
  93.         OnScreenDrives$ = OnScreenDrives$ + "[" + MID$(Drives$, Driv, 1) + ":] "
  94.     NEXT Driv
  95.     IF LEN(OnScreenDrives$) > lenght THEN OnScreenDrives$ = LEFT$(OnScreenDrives$, lenght - 3) + LTRIM$("...")
  96.  
  97.     IF Lb = 0 AND le = 0 THEN
  98.         Lb = 1
  99.         le = 20
  100.     END IF
  101.  
  102.     IF INSTR(1, _OS$, "WINDOWS") THEN sel$ = CHR$(92)
  103.     IF INSTR(1, _OS$, "LINUX") THEN sel$ = "/"
  104.     first = 1
  105.  
  106.  
  107.  
  108.     DO
  109.         K& = _KEYHIT
  110.         iink$ = UCASE$(INKEY$)
  111.         IF LEN(iink$) THEN
  112.             IF INSTR(1, Drives$, iink$) THEN
  113.                 newdrive$ = iink$ + ":": CHDIR newdrive$: EXIT FUNCTION
  114.             END IF
  115.             iink$ = ""
  116.         END IF
  117.         oldposx = posx
  118.         IF first THEN oldposx = -1: first = 0
  119.  
  120.  
  121.         'mouse support ---
  122.  
  123.         WHILE _MOUSEINPUT
  124.             MoX = _MOUSEX: MoY = _MOUSEY
  125.             IF MoX > X AND MoX < X + ((lenght + 4) * 8) AND MoY > Y AND MoY < Y + (height * 20) + 40 THEN 'podle LINE
  126.  
  127.                 poloha = _CEIL((MoY - Y - 20) / 20) 'pro mys
  128.  
  129.  
  130.                 IF UseWheel THEN ' in function last parameter: 0 = use wheel, 1 = not use wheel
  131.                     SELECT CASE SGN(_MOUSEWHEEL)
  132.                         CASE -1: K& = 18432
  133.                         CASE 1: K& = 20480
  134.                     END SELECT
  135.  
  136.                 ELSE
  137.  
  138.  
  139.                     IF poloha < posx - Lb THEN K& = 18432
  140.                     IF poloha > posx - Lb THEN K& = 20480
  141.                 END IF
  142.  
  143.  
  144.  
  145.                 IF _MOUSEBUTTON(1) AND poloha >= Lb AND poloha <= le THEN
  146.                     IF MoX < (8 * lenght) + X THEN K& = 13: _DELAY .1
  147.  
  148.                 END IF
  149.  
  150.  
  151.  
  152.                 IF _MOUSEBUTTON(1) AND MoX > (8 * lenght) + X AND MoY < Y + 16 THEN 'mouse / up arrow
  153.                     K& = 18432
  154.                 END IF
  155.  
  156.  
  157.                 IF _MOUSEBUTTON(1) AND MoX > (8 * lenght) + X AND MoY > Y + (height * 20) + 24 THEN 'mouse / down arrow
  158.                     K& = 20480
  159.                 END IF
  160.             END IF
  161.  
  162.             'podpora prepnuti disku mysi: drive select mouse support (alfa - not full tested)
  163.  
  164.             IF MoX >= X + 10 AND MoX < X + 10 + (8 * LEN(OnScreenDrives$)) - 8 AND MoY >= (Y + 20 * height) + 50 AND MoY < (Y + 20 * height) + 66 THEN
  165.                 IF _MOUSEBUTTON(1) THEN
  166.                     DiskSel = _CEIL(((MoX - X + 10) / 8) / 6)
  167.                     IF DiskSel > LEN(Drives$) THEN DiskSel = LEN(DiskSel)
  168.                     iink$ = MID$(Drives$, DiskSel, 1)
  169.                     newdrive$ = iink$ + ":": CHDIR newdrive$: EXIT FUNCTION
  170.                 END IF
  171.             END IF
  172.  
  173.         WEND
  174.         '------------------
  175.  
  176.  
  177.         ' --- keyboard inputs
  178.         SELECT CASE K&
  179.             CASE 18432: posx = posx - 1: GU = 1: GD = 0 'marks: Go down disabled, go up enbabled
  180.             CASE 20480: posx = posx + 1: GU = 0: GD = 1 'marks: Go down enabled, go up disabled
  181.             CASE 13: Browse$ = _CWD$ + sel$ + arr(posx) + dd$: EXIT FUNCTION 'or if your choice is array record number then return PosX and erase $ in func name 'directory move is solved in my loop
  182.             CASE 27: Browse$ = "---E": EXIT FUNCTION
  183.             CASE 32:
  184.         END SELECT
  185.         ' -------------------
  186.  
  187.         'if is link selected (not dir):
  188.         IF UBOUND(arr) < 0 THEN EXIT FUNCTION 'Browse$ = LEFT$(_CWD$, 3): EXIT FUNCTION
  189.         'end of bug repair
  190.  
  191.         IF posx <= 0 THEN posx = 0: Lb = 0: le = Lb + height
  192.         IF posx > UBOUND(arr) - 1 THEN posx = UBOUND(arr) - 1
  193.         IF oldposx <> posx THEN
  194.             IF posx > le AND GD THEN Lb = Lb + 1: le = le + 1
  195.             IF GU AND posx < Lb THEN Lb = Lb - 1: le = le - 1
  196.             textpos = 0
  197.             IF le > UBOUND(arr) THEN le = UBOUND(arr)
  198.             IF le - Lb > height THEN le = Lb + height
  199.             IF Lb > le THEN EXIT FUNCTION
  200.  
  201.  
  202.             FOR V = Lb TO le 'List Begin to List End
  203.                 textpos = textpos + 20 'row is 20 pixel height
  204.                 IF V = posx THEN
  205.                     COLOR InPosColor&, ListColor&
  206.                 ELSE
  207.                     IF V > numDirs - 1 THEN COLOR ListColor& ELSE COLOR DirColor&
  208.                     IF posx <= numDirs - 1 THEN dd$ = ".DIR." ELSE dd$ = ""
  209.                 END IF
  210.                 text$ = arr(V)
  211.                 IF LEN(text$) > lenght - 2 THEN text$ = LEFT$(text$, lenght - 4) + LTRIM$("...") ELSE text$ = text$ + SPACE$(lenght - LEN(text$) - 1)
  212.                 _PRINTSTRING (X + 10, Y + textpos), text$
  213.                 COLOR ListColor&, _RGB32(0, 0, 0)
  214.  
  215.  
  216.                 possss = posx + 1
  217.  
  218.  
  219.                 Posuvnik_V_Procentech! = (possss / UBOUND(arr))
  220.  
  221.                 '----------------------------------------------------------------------- dodelat
  222.                 WindowHeight = (23 + height * 20) - 40
  223.                 OldGC = GC
  224.                 GC = Y + WindowHeight * Posuvnik_V_Procentech!
  225.  
  226.                 COLOR _RGB32(0, 0, 0)
  227.                 _PRINTSTRING (X + 5 + lenght * _FONTWIDTH, OldGC + 22), CHR$(222)
  228.                 COLOR _RGB32(127, 127, 127)
  229.                 _PRINTSTRING (X + 5 + lenght * _FONTWIDTH, GC + 22), CHR$(222)
  230.  
  231.                 _PRINTSTRING (X + 5 + lenght * _FONTWIDTH, Y + 7), CHR$(24)
  232.                 _PRINTSTRING (X + 5 + lenght * _FONTWIDTH, 3 + Y + 20 + height * 20), CHR$(25)
  233.                 '---------------------------------------------------------------------------
  234.  
  235.             NEXT V
  236.  
  237.             diskar:
  238.             COLOR _RGB32(255, 255, 0)
  239.             _PRINTSTRING (X + 10, (Y + 20 * height) + 50), OnScreenDrives$
  240.             COLOR _RGB32(255, 205, 249)
  241.             CWD$ = _CWD$
  242.             IF LEN(CWD$) > lenght THEN CWD$ = LEFT$(CWD$, lenght - 3) + LTRIM$("...")
  243.             _PRINTSTRING (X + 10, (Y + 20 * height) + 70), CWD$
  244.         END IF
  245.  
  246.         LINE (X + 1, Y + 1)-(X + 3 + (8 * lenght) + 16, Y + 3 + (20 * height) + 90), , B
  247.         LINE (X + 4, Y + 4)-(X + (8 * lenght) + 16, Y + (20 * height) + 90), , B
  248.         LINE (X + 4, Y + (height * 20) + 40)-(X + (8 * lenght) + 16, Y + (height * 20) + 40), , B
  249.  
  250.  
  251.  
  252.         _LIMIT 80
  253.     LOOP
  254.  
  255. FUNCTION LoadDrives$ (drives() AS STRING)
  256.     IF INSTR(_OS$, "[WINDOWS]") THEN
  257.         SHELL _HIDE CHR$(34) + "wmic logicaldisk get name" + CHR$(34) + ">TempDirList.txt"
  258.         REDIM drives(0) AS STRING
  259.  
  260.         OPEN "TempDirList.txt" FOR INPUT AS #1
  261.         LINE INPUT #1, junk$ 'First line is  name
  262.         counter = 0
  263.         DO UNTIL EOF(1)
  264.             counter = counter + 1
  265.             INPUT #1, junk$ 'drive name
  266.             REDIM _PRESERVE drives(counter) AS STRING
  267.             IF LEN(junk$) > 1 THEN junk$ = MID$(junk$, 2, 1) + ":" ELSE junk$ = "": counter = counter - 1
  268.             IF junk$ <> "" THEN
  269.                 drives(counter) = junk$
  270.             END IF
  271.         LOOP
  272.         CLOSE #1
  273.         KILL "TempDirList.txt"
  274.  
  275.         FOR manual = 1 TO counter
  276.             LoadDrives$ = LoadDrives$ + LEFT$(drives(manual), 1)
  277.         NEXT
  278.     END IF
  279.  
  280. SUB GetFileList (SearchDirectory AS STRING, DirList() AS STRING, FileList() AS STRING)
  281.     CONST IS_DIR = 1
  282.     CONST IS_FILE = 2
  283.     DIM flags AS LONG, file_size AS LONG
  284.  
  285.     REDIM _PRESERVE DirList(100), FileList(100)
  286.     DirCount = 0: FileCount = 0
  287.  
  288.   IF load_dir(SearchDirectory + CHR$(0)) THEN
  289.         DO
  290.             length = has_next_entry
  291.             IF length > -1 THEN
  292.                 nam$ = SPACE$(length)
  293.                 get_next_entry nam$, flags, file_size
  294.                 IF flags AND IS_DIR THEN
  295.                     DirCount = DirCount + 1
  296.                     IF DirCount > UBOUND(DirList) THEN REDIM _PRESERVE DirList(UBOUND(DirList) + 100)
  297.                     DirList(DirCount) = nam$
  298.                 ELSEIF flags AND IS_FILE THEN
  299.                     FileCount = FileCount + 1
  300.                     IF FileCount > UBOUND(filelist) THEN REDIM _PRESERVE FileList(UBOUND(filelist) + 100)
  301.                     FileList(FileCount) = nam$
  302.                 END IF
  303.             END IF
  304.         LOOP UNTIL length = -1
  305.      rem   close_dir
  306.     ELSE
  307.     END IF
  308.     close_dir
  309.     REDIM _PRESERVE DirList(DirCount)
  310.     REDIM _PRESERVE FileList(FileCount)
  311.  
* direntry.h (Filesize: 1.15 KB, Downloads: 170)
« Last Edit: June 27, 2020, 09:38:09 am by Petr »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Browsing Directories / files using Steve´s library
« Reply #10 on: June 25, 2020, 05:34:09 am »
Note Petr:  Line 315 is close_dir.... Move that to after the  END IF to avoid issues with things not working properly in all cases.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Browsing Directories / files using Steve´s library
« Reply #11 on: June 25, 2020, 05:53:12 am »
Last source code upgraded, Steve :)

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Browsing Directories / files using Steve´s library
« Reply #12 on: June 26, 2020, 08:48:17 pm »
Last source code upgraded, Steve :)

One more fix -- line 298:

 
    IF load_dir(SearchDirectory + CHR$(0)) THEN
 

Those search strings need to be null terminated to function properly with our POSIX library calls.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Browsing Directories / files using Steve´s library
« Reply #13 on: June 26, 2020, 10:38:00 pm »
Wow! This is exactly what I was looking for today for Paint Pixels 7. Is there a way to mask the files to display only .jpg files? I'm looking it over quickly but can't find anything yet. I haven't put it on Paint Pixels yet though, so we'll see if they can work together good. But first I want to see if I can mask the names.

Edit: I am trying another one first.
« Last Edit: June 27, 2020, 02:18:07 am by SierraKen »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Browsing Directories / files using Steve´s library
« Reply #14 on: June 27, 2020, 09:38:43 am »
More fix to row 298 added :)