It is currently Tue May 23, 2017 9:50 am



Welcome
Welcome to rfobasic

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today. **You are not required to provide truthful information to any registration questions. Be whomever you wish to be.!


Post new topic Reply to topic  [ 12 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: File Dialog/Explorer For Selecting Files
Unread postPosted: Mon May 15, 2017 1:16 am 
Offline

Joined: Mon May 15, 2017 1:11 am
Posts: 4
Hi everyone! Just started using RFO and it's just great. The documentation is pretty detailed too but I cannot seem to find any section on file selection. I am writing a small routine that takes a photo and sends it to my FTP server. How would I open the device file system to browse and select a file?

Thanks in advance! :)


Report this post
Top
 Profile  
 
 Post subject: Re: File Dialog/Explorer For Selecting Files
Unread postPosted: Tue May 16, 2017 3:42 am 
Offline

Joined: Mon Oct 22, 2012 7:32 am
Posts: 138
Not sure this will help, but here is a routine I wrote when BASIC! first came out. Later releases of BASIC! probably makes this a lot easier.
I ripped the code form a system (ionSQL) , I wrote back then. If you want to see it work just get the system from google play "sqlite eyes on" and try it.
I was looking for certain files - typFile$, but you can change that to what you want , or simply return all selected files.

Code:
! ---------------------------------------------------
! Choose file from Directory
! ----------------------------------------------------
chooseFile:
ddrPath$ = ""
file.root root$
root$ = ".."+root$ + "/"
ddrLvl = 0
for i = 1 to len(root$)
    i = is_in("/",root$,i+1)
    if i = 0 then F_N.break
    ddrLvl = ddrLvl + 1
next i
array.delete dr$[]
dim dr$[100]
for i = 1 to ddrLvl
    dr$[i] = word$(root$,i,"/") + "/"
next i
ddrLoop:
! Get the listing from the path directory
! and sort it
ARRAY.DELETE d1$[]
FILE.DIR ddrPath$, d1$[]
ARRAY.LENGTH length, d1$[]
if d1$[1] = "" then length = length - 1
for i = 1 to length
    d1$[i] = lower$(d1$[i]) + " __^^__"+d1$[i]
next i
array.sort d1$[]
ARRAY.DELETE d2$[]
DIM d2$[length+1]
d2$[1] = ".."
FOR i = 1 TO length
    j = is_in("__^^__",d1$[i])
    d2$[i + 1] = mid$(d1$[i],j+6)
NEXT i
h1$ = "<center><table border=1 cellpadding=0 cellspacing=0 bgcolor="+clrBkg$+">" +~
"<tr align=center bgcolor="+clrHdr$+"><td colspan=2>" +~
"<span style='font-family: Arial;'><B>Path: "+ddrPath$+"<br> Count:"+format$("####",length) +~
" level:"+format$("###",ddrLvl) + "<br>Dir:"+root$ +~
"<TR><TD colspan=2 BGCOLOR="+clrHdr$+">" +~
"<input type=button value='Exit' onClick=\"doDataLink('ext|"+ddrPath$+"')\"/>" +~
"</TD></TR><TR align=center bgcolor="+clrHdr$+">" +~
"<TD>Name</TD><TD>Size</TD></TR>"
h2$= ""
for i = 1 to length + 1
    thisFile$ = ddrPath$+d2$[i]
    thisName$ = d2$[i]
    if length > 100 & mod(i,20) = 0 then
        infMsg$ = "Working .. Count:"+format$("#####",i)+" "+thisName$
        gosub shoProgress
    endif
    siz$ = ""
    if is_in("(d)",d2$[i]) = 0 & d2$[i] <> ".." then
        file.exists exst,thisFile$
        if exst <> 0 then
            file.size siz,thisFile$
            siz$ = format$("#########",siz)
        endif
    endif
    h2$=h2$+"<TR><TD>" +~
    "<input type=button value='"+d2$[i]+"' onClick=\"doDataLink('sel|"+str$(i)+"')\"/></TD>" +~
    "<TD align=right>"+siz$+"</TD>"
next i
h$=hd$+m$+h1$+h2$+"</table></body></html>"
gosub userInput
ddrUserRqst:
fctn$ = left$(data$,3)
if fctn$ = "ext" then goto ddrExit
s$ = mid$(data$,5)
s = val(s$)
IF s > 1
    n = IS_IN("(d)", d2$[s])
    IF n = 0 then
        thisFile$ = ddrPath$+d2$[s]
        thisName$ = d2$[s]
        popup "File:"+thisFile$,0,0,0
       
        for dj = 0 to len(thisName$)
            dj = is_in(".",thisName$,dj+1)
            if dj = 0 then F_N.break
            di = dj
        next i
        if di = 0 then
            filExt$ = "unk"
            else
            filExt$ = lower$(mid$(thisName$,di+1))
        endif
        if typFile$ = "sql" then RETURN
        if typFile$ = "csv" then RETURN
        if typFile$ = "db" then
            thisName$ = d2$[s]
            byte.open r,f,thisFile$
            byte.read.buffer f,13,data$
            byte.close f
            if is_in("SQLite format",data$) = 0 then
                errMsg$ = "File "+thisFile$+" is not a SQLite file"
                gosub shoMsg
                popup "File "+thisFile$+" is not a SQLite file",0,0,0
                html.load.url thisFile$
                gosub userInput1
                goto dbRequest
                else
                infMsg$ = "SQLite file:"+thisFile$
                RETURN
            endif
        endif
        gosub userInput1
        goto ddrUserRqst
        !  GOTO ddrLoop
    ENDIF
    dname$ = LEFT$(d2$[s],n-1)
    ddrPath$=ddrPath$+dname$+"/"
    root$      = ""
    ddrLvl      = ddrLvl+ 1
    dr$[ddrLvl]   = dname$ + "/"
    for i = 1 to ddrLvl
        root$ = root$ + dr$[i]
    next i
    GOTO ddrLoop
ENDIF
! If s = 1 then must back one level
! if at start path then back up one level
IF ddrPath$ = ""
    ddrPath$ = "../"
    ddrLvl = ddrLvl -1
    root$ = ""
    for i = 1 to ddrLvl
        root$ = root$ + dr$[i]
    next i
    GOTO ddrLoop
ENDIF
! Not at start path split the path by  the "/" chars
ARRAY.DELETE p$[]
SPLIT p$[], ddrPath$, "/"
ARRAY.LENGTH length, p$[]
! If the last entry is ".." then add "../" to back up one level
IF p$[length] = ".."
    ddrPath$ = ddrPath$ + "../"
    ddrLvl = ddrLvl -1
    root$ = ""
    for i = 1 to ddrLvl
        root$ = root$ + dr$[i]
    next i
    GOTO ddrLoop
ENDIF
! Last entry is not ".." so must delete the
! last directory from the path  If only one entry then path is back
! to the base path
IF length = 1
    ddrPath$ = ""
    file.root root$
    root$ = ".."+root$+"/"
    GOTO ddrLoop
ENDIF
! Reconstruct path without the last directory
ddrPath$ = ""
FOR i = 1 TO length - 1
    ddrPath$ = ddrPath$ + p$[i] + "/"
NEXT i
root$ = ""
ddrLvl = ddrLvl -1
FOR i = 1 TO length - 1
    path$ = path$ + p$[i] + "/"
next i
for i = 1 to ddrLvl
    root$ = root$ + dr$[i]
NEXT i
GOTO ddrLoop
ddrExit:
rqst$ = "ext"
RETURN


Report this post
Top
 Profile  
 
 Post subject: Re: File Dialog/Explorer For Selecting Files
Unread postPosted: Tue May 16, 2017 8:35 am 
Offline

Joined: Sat Dec 22, 2012 2:32 pm
Posts: 830
Here another attempt (very quick&dirty, not tested deeply, no filter-option(s) yet...)

brochi


Code:
FN.DEF            selectFile$()

path$           = "../../"
STACK.CREATE      s, pathes
LIST.CREATE       s,files

upwards$        = ".."
_dirMarker$     = "(dir)"


DO

  STACK.ISEMPTY    pathes, stackIsEmpty
  FILE.DIR         path$ ,  files$[] , "(dir)"
  LIST.CLEAR       files
  IF               !stackIsEmpty THEN  LIST.ADD files, upwards$
  LIST.ADD.ARRAY   files, files$[]
  LIST.TOARRAY     files, files$[]

  DIALOG.SELECT    sel, files$[], "Select file..."

  IF files$[sel] = upwards$

   STACK.POP       pathes, path$

  ELSE

   STACK.PUSH       pathes, path$
   path$         += REPLACE$(files$[sel], _dirMarker$ ,"")+"/"

  ENDIF

UNTIL             !is_in (_dirMarker$ , files$[sel]) & sel>1

FN.RTN             path$ +files$[sel]

FN.END





!--------------
DO

  selFile$        = selectFile$()

PRINT              selFile$
print

PAUSE 1000

UNTIL forever
!--------------

END


Report this post
Top
 Profile  
 
 Post subject: Re: File Dialog/Explorer For Selecting Files
Unread postPosted: Tue May 16, 2017 10:08 am 
Offline

Joined: Sat Mar 02, 2013 11:04 am
Posts: 836
Location: France
Always as efficient brochi :)

_________________
"It is better to mobilize intelligence for stupid things, rather than mobilizing stupidity for intelligent things."
Galaxy TAB S 8.4, 2560x1600, Marshmallow 6.0.1
Galaxy Note II, 1280x720, JB4.1.2
Galaxy A3, 1280x720, Android 6.0.1


Report this post
Top
 Profile  
 
 Post subject: Re: File Dialog/Explorer For Selecting Files
Unread postPosted: Wed May 17, 2017 9:14 pm 
Offline

Joined: Mon May 15, 2017 1:11 am
Posts: 4
Thank you very much, brochi and kokenge!

@kokenge: I've learned a lot from your code, but it fails with "Undefined Label userinput".

@brochi: Wow! All that with so little code. I'm still trying to figure it out, but it's great.

Once again, very much appreciated. Thank you!


Report this post
Top
 Profile  
 
 Post subject: Re: File Dialog/Explorer For Selecting Files
Unread postPosted: Fri May 19, 2017 1:41 am 
Offline

Joined: Mon Oct 22, 2012 7:32 am
Posts: 138
Quote:
ut fails with "Undefined Label userinput".

Sorry about that.
I ripped the code from a program I wrote a long time ago. Just to make sure there is not other missing code the best thing is to download the program and try it.
You can download;
Source at http://kneware.com/ionsql/source/
Docs at http://kneware.com/ionsql/

Hope this heps.


Report this post
Top
 Profile  
 
 Post subject: Re: File Dialog/Explorer For Selecting Files
Unread postPosted: Sat May 20, 2017 10:28 pm 
Offline
User avatar

Joined: Sat Mar 26, 2016 9:23 am
Posts: 92
Feels very forth-ish, brochi.

:)

brochi wrote:
Here another attempt (very quick&dirty, not tested deeply, no filter-option(s) yet...)

brochi


Code:
FN.DEF            selectFile$()

path$           = "../../"
STACK.CREATE      s, pathes
LIST.CREATE       s,files

upwards$        = ".."
_dirMarker$     = "(dir)"


DO

  STACK.ISEMPTY    pathes, stackIsEmpty
  FILE.DIR         path$ ,  files$[] , "(dir)"
  LIST.CLEAR       files
  IF               !stackIsEmpty THEN  LIST.ADD files, upwards$
  LIST.ADD.ARRAY   files, files$[]
  LIST.TOARRAY     files, files$[]

  DIALOG.SELECT    sel, files$[], "Select file..."

  IF files$[sel] = upwards$

   STACK.POP       pathes, path$

  ELSE

   STACK.PUSH       pathes, path$
   path$         += REPLACE$(files$[sel], _dirMarker$ ,"")+"/"

  ENDIF

UNTIL             !is_in (_dirMarker$ , files$[sel]) & sel>1

FN.RTN             path$ +files$[sel]

FN.END





!--------------
DO

  selFile$        = selectFile$()

PRINT              selFile$
print

PAUSE 1000

UNTIL forever
!--------------

END


Report this post
Top
 Profile  
 
 Post subject: Re: File Dialog/Explorer For Selecting Files
Unread postPosted: Sun May 21, 2017 4:39 am 
Offline

Joined: Sat Dec 22, 2012 2:32 pm
Posts: 830
@cavelamb: you speak FORTH ?

------------

general: when useing ARRAY.COPY instead of LIST.xxx and useing a more suitabale "dir-marker", it bevomes slightly more compact....
Code:
FN.DEF            selectFile2$()
pa$            = "../../"
up$            = ".."
STACK.CREATE     s, pa
DO
  FILE.DIR        pa$ ,  tmp$[] , "/"
  STACK.ISEMPTY   pa, sIe
  UNDIM           fi$[]
  IF             !sIe THEN ARRAY.COPY tmp$[],fi$[-1] : fi$[1]=up$
  IF              sIe THEN ARRAY.COPY tmp$[],fi$[]
  DIALOG.SELECT   sel, fi$[] , "Select..."
  IF              fi$[sel]=up$ THEN STACK.POP  pa,pa$
  IF             !fi$[sel]=up$ THEN STACK.PUSH pa,pa$ : pa$+=fi$[sel]
UNTIL           !RIGHT$(fi$[sel],1)="/" & sel>1
FN.RTN           pa$ 
FN.END


!--------------
DO
selFile$        = selectFile2$()
PRINT             selFile$
PRINT
PAUSE             1000
UNTIL              forever
!--------------


Report this post
Top
 Profile  
 
 Post subject: Re: File Dialog/Explorer For Selecting Files
Unread postPosted: Sun May 21, 2017 5:44 am 
Offline

Joined: Tue Dec 04, 2012 10:50 am
Posts: 656
Location: UK
brochi wrote:
@cavelamb: you speak FORTH ?

Perhaps he just uses (goes) FORTH to multiply! ;-)

Mike.


Report this post
Top
 Profile  
 
 Post subject: Re: File Dialog/Explorer For Selecting Files
Unread postPosted: Sun May 21, 2017 7:05 am 
Offline

Joined: Sat Mar 02, 2013 11:04 am
Posts: 836
Location: France
Just a small question brochi : each time you declare a LIST or a STACK or an ARRAY into a function it's not deleted at the exit of this function, right?

Gilles

_________________
"It is better to mobilize intelligence for stupid things, rather than mobilizing stupidity for intelligent things."
Galaxy TAB S 8.4, 2560x1600, Marshmallow 6.0.1
Galaxy Note II, 1280x720, JB4.1.2
Galaxy A3, 1280x720, Android 6.0.1


Report this post
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ]  Go to page 1, 2  Next


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
suspicion-preferred