Posts: 2,177
Threads: 222
Joined: Apr 2022
Reputation:
104
_OpenFileDialog$()
So let's say I use this beat new addition to qb. It opens my local directory (c:\QB64pe), but now I use that dialog box to go to a different folder: c:\Pete's Tremendous-Steve's-Just-Amazing and I open a file from that location. So what do I query to get that non-local directory into a string variable like dir$ in my code?
Pete
Posts: 34
Threads: 6
Joined: Apr 2024
Reputation:
5
(10-27-2024, 12:10 AM)Pete Wrote: _OpenFileDialog$()
So let's say I use this beat new addition to qb. It opens my local directory (c:\QB64pe), but now I use that dialog box to go to a different folder: c:\Pete's Tremendous-Steve's-Just-Amazing and I open a file from that location. So what do I query to get that non-local directory into a string variable like dir$ in my code?
Pete
Pete the string$ returned from OpenFileDialog$ is the entire Pathname of the file chosen. You just snip off the 'Name' part of the string to get the full path.
Posts: 2,177
Threads: 222
Joined: Apr 2022
Reputation:
104
10-27-2024, 12:54 AM
(This post was last modified: 10-27-2024, 12:56 AM by Pete.)
Neat! +1
Code: (Select All)
target$ = _OpenFileDialog$("Pick a folder and a file.", "")
dir$ = Mid$(target$, 1, _InStrRev(target$, "\"))
file$ = Mid$(target$, Len(dir$) + 1)
Print dir$
Print file$
find$ = _OpenFileDialog$("Look, here's your file!", file$)
Shell _DontWait "explorer /select, " + dir$ + file$
So now I see I can get the file info and use it locate itself, similar to how we used to do it in the SHELL example, with one exception, it does not highlight the file in the menu, instead it places the file name in the dialog open box.
Thanks!
Pete
Oh, BTW: I stared programming in BASIC in 1981. TI 4A. When 4K was all anybody would ever need!
Shoot first and shoot people who ask questions, later.
Posts: 34
Threads: 6
Joined: Apr 2024
Reputation:
5
10-27-2024, 01:31 AM
(This post was last modified: 10-27-2024, 01:38 AM by ahenry3068.)
(10-27-2024, 12:54 AM)Pete Wrote: Neat! +1
Code: (Select All)
target$ = _OpenFileDialog$("Pick a folder and a file.", "")
dir$ = Mid$(target$, 1, _InStrRev(target$, "\"))
file$ = Mid$(target$, Len(dir$) + 1)
Print dir$
Print file$
find$ = _OpenFileDialog$("Look, here's your file!", file$)
Shell _DontWait "explorer /select, " + dir$ + file$
So now I see I can get the file info and use it locate itself, similar to how we used to do it in the SHELL example, with one exception, it does not highlight the file in the menu, instead it places the file name in the dialog open box.
Thanks!
Pete
Oh, BTW: I stared programming in BASIC in 1981. TI 4A. When 4K was all anybody would ever need!
I started programming BASIC in 1985 but on 'Big Iron'. I had 1mb of user Ram & 1.6gb's of Hard drive space available to me. (I'll let you guess how much those '4' storage devices weighed). And I had all the colors in the World I needed as long as they were Black or Green. (The 'Big Iron' was a Harris Systems mini computer running 'Virtual Operating System V' ) I didn't own my own system until about 3 years later when I bought a Tandy 1000 TX (and Maxed out a brand new Radio Shack credit card for that) ...
Posts: 34
Threads: 6
Joined: Apr 2024
Reputation:
5
(10-27-2024, 01:31 AM)ahenry3068 Wrote: (10-27-2024, 12:54 AM)Pete Wrote: Neat! +1
Code: (Select All)
target$ = _OpenFileDialog$("Pick a folder and a file.", "")
dir$ = Mid$(target$, 1, _InStrRev(target$, "\"))
file$ = Mid$(target$, Len(dir$) + 1)
Print dir$
Print file$
find$ = _OpenFileDialog$("Look, here's your file!", file$)
Shell _DontWait "explorer /select, " + dir$ + file$
So now I see I can get the file info and use it locate itself, similar to how we used to do it in the SHELL example, with one exception, it does not highlight the file in the menu, instead it places the file name in the dialog open box.
Thanks!
Pete
Oh, BTW: I stared programming in BASIC in 1981. TI 4A. When 4K was all anybody would ever need!
I started programming BASIC in 1985 but on 'Big Iron'. I had 1mb of user Ram & 1.6gb's of Hard drive space available to me. (I'll let you guess how much those '4' storage devices weighed). And I had all the colors in the World I needed as long as they were Black or Green. (The 'Big Iron' was a Harris Systems mini computer running 'Virtual Operating System V' ) I didn't own my own system until about 3 years later when I bought a Tandy 1000 TX (and Maxed out a brand new Radio Shack credit card for that) ... I find the following useful
Function GetFileExt$ (FName$)
DOT$ = "."
L = Len(FName$)
TMP$ = ""
If InStr(1, FName$, DOT$) = 0 Then GoTo Skipall
For I = L To 1 Step -1
C$ = Mid$(FName$, I, 1)
TMP$ = C$ + TMP$
If C$ = DOT$ Then Exit For
Next I
Skipall:
GetFileExt = TMP$
End Function
Function GetFileName$ (FName$)
$If WINDOWS Then
SLASH$ = "\"
$Else
SLASH$ = "/"
$End If
TMP$ = ""
T$ = GetFileExt(FName$)
CUT = Len(T$)
L = Len(FName$)
TName$ = Left$(FName$, L - CUT)
If InStr(1, TName$, SLASH$) = 0 Then
TMP$ = TName$
GoTo Skiploop
End If
For I = Len(TName$) To 1 Step -1
C$ = Mid$(TName$, I, 1)
If C$ <> SLASH$ Then
TMP$ = C$ + TMP$
Else
Exit For
End If
Next I
Skiploop:
GetFileName = TMP$
End Function
Function GetFilePath$ (FName$)
t1$ = GetFileExt(FName$)
t2$ = GetFileName(FName$)
L = Len(FName$) - (Len(t1$) + Len(t2$))
GetFilePath$ = Left$(FName$, L)
End Function
Posts: 2,177
Threads: 222
Joined: Apr 2022
Reputation:
104
Takes me back to the days when we had to parse SHELL dir calls. Whomever created the /b switch (bare files) was a friggin' genius.
Yeah, who got it right backslash Windows or forward slash Unix and everything else? Maybe Gates was dyslexic... Oh wait, I meant demonic.
Pete
|