Author |
Topic: *CHDIR + OPENIN with wildcard = wrong folder (Read 537 times) |
|
5against4
New Member
member is offline


Posts: 16
|
 |
*CHDIR + OPENIN with wildcard = wrong folder
« Thread started on: Sep 21st, 2015, 2:41pm » |
|
When i change directory using *CHDIR, and then use OPENIN with a wildcard so that the Open File dialogue box is displayed, the folder shown in the dialogue box is not the one i've just changed to but the original one (i.e. the one in which the program itself is stored).
Am i missing something or is this just the way BBC Basic wants to behave? i need the Open File dialogue box to show me the contents of the folder i've changed to, not the default one.
|
|
Logged
|
|
|
|
sveinioslo
Developer
member is offline


Posts: 64
|
 |
Re: *CHDIR + OPENIN with wildcard = wrong folder
« Reply #1 on: Sep 21st, 2015, 5:37pm » |
|
Manual info, at pages: 'Setting the File Open dialogue's initial directory' and 'Using dialogue boxes'
Replace *CHDIR with this: Code:
DIM fs{lStructSize%, hwndOwner%, hInstance%, lpstrFilter%, \
\ lpstrCustomFilter%, nMaxCustFilter%, nFilterIndex%, \
\ lpstrFile%, nMaxFile%, lpstrFileTitle%, \
\ nMaxFileTitle%, lpstrInitialDir%, lpstrTitle%, \
\ flags%, nFileOffset{l&,h&}, nFileExtension{l&,h&}, \
\ lpstrDefExt%, lCustData%, lpfnHook%, lpTemplateName%}
DIM fp% 255
InitialDir$ = "C:\___SOMEWHERE___"+CHR$0 : REM Change here ...................
FileFilter$ = "*:*"+CHR$0+CHR$0
fs.lStructSize% = DIM(fs{})
fs.hwndOwner% = @hwnd%
fs.lpstrFilter% = !^FileFilter$
fs.lpstrFile% = fp%
fs.nMaxFile% = 256
fs.lpstrInitialDir% = !^InitialDir$
fs.flags% = 6
Replace OPENIN"*" with this: Code:
SYS "GetOpenFileName", fs{} TO result%
IF result% THEN file$=$$fp% : PRINT file$
Hope this helps. Svein
|
« Last Edit: Sep 22nd, 2015, 06:06am by sveinioslo » |
Logged
|
|
|
|
5against4
New Member
member is offline


Posts: 16
|
 |
Re: *CHDIR + OPENIN with wildcard = wrong folder
« Reply #2 on: Sep 21st, 2015, 8:38pm » |
|
Thanks Svein - it's a shame (and a bit ridiculous) it needs to be as complex as that! But i'm grateful for the help
|
|
Logged
|
|
|
|
hellomike
New Member
member is offline


Gender: 
Posts: 46
|
 |
Re: *CHDIR + OPENIN with wildcard = wrong folder
« Reply #3 on: Sep 21st, 2015, 9:45pm » |
|
Hi,
Probably I don't understand what you want but why use *CHDIR at all?
Whats wrong with this? Code: SearchDir$="C:\Windows\System32\"
F%=OPENIN(SearchDir$+"*.xml")
IF F%=0 ERROR 100,"File not found."
Line1$=GET$#F%
CLOSE#F%
PRINT "This program is stored in: "+@dir$
PRINT "First line in the chosen XML was: '"+Line1$+"'"
END
Cheers,
Mike
|
|
Logged
|
|
|
|
5against4
New Member
member is offline


Posts: 16
|
 |
Re: *CHDIR + OPENIN with wildcard = wrong folder
« Reply #4 on: Sep 22nd, 2015, 09:09am » |
|
That's quite nice Mike, thanks!
However - is it possible to make the search directory relative rather than absolute? i have a subfolder called DATA and want it to look in there, but nothing seems to tell it to look in there unless i specify the full absolute location.
But otherwise your solution is perfect - thank you!
|
« Last Edit: Sep 22nd, 2015, 09:26am by 5against4 » |
Logged
|
|
|
|
DDRM
Administrator
member is offline


Gender: 
Posts: 321
|
 |
Re: *CHDIR + OPENIN with wildcard = wrong folder
« Reply #5 on: Sep 22nd, 2015, 1:24pm » |
|
Hi,
Does @dir$ do what you need? That is set to the directory from which the program was loaded, so if your DATA folder is in there you could refer to it as @dir$+"DATA\*.bbc"
Hope that helps,
D
|
|
Logged
|
|
|
|
hellomike
New Member
member is offline


Gender: 
Posts: 46
|
 |
Re: *CHDIR + OPENIN with wildcard = wrong folder
« Reply #6 on: Sep 22nd, 2015, 4:14pm » |
|
As far as I know, the OPENIN() function either needs an absolute/full path or, if it doesn't have that, e.g. because you are using it like
F% = OPENIN("*.*")
,it will make the Open File dialogue box relative to the content of what's in the @dir$ variable, NOT to the current working folder.
But no worries. You can easily find out the absolute path for the current working folder at any given time and then append "\DATA\*.*" to it as follows:
Code: ......
REM Get absolute path to working folder.
DIM cd% 255
SYS "GetCurrentDirectory", 256, cd%
PRINT $$cd%
REM Show Open File dialogue box relative to it...
F% = OPENIN($$cd%+"\DATA\*.*")
......
This way you provide OPENIN() with an absolute path.
If you need that more often in the source, you better use the function as documented in the Help for the *CHDIR command.
Then the OPENIN() call would be:
Code: F% = OPENIN(FNcurrentdirectory+"\DATA\*.*")
Happy coding.
Mike
|
|
Logged
|
|
|
|
|