Uses app path instead of curr path for file.open

Here one can report bugs or hold discussions about bugs updates and work arounds.
Post Reply
rdcoder1
Posts: 4
Joined: Mon Jul 23, 2012 4:01 pm

Uses app path instead of curr path for file.open

Post: # 910Post rdcoder1
Mon Jul 23, 2012 4:35 pm

Running FNXBasic 2.1 apr_2012 and compiling for XP x86 & Win7 x64 - symptom is on both. I admit I`ve only had FNXB a few days since I switched from QB64 (didn`t like the HUGE set of runtime DLLs). I also admit I`m using it for CLI apps, and yea its really suited for Visual-type apps, but I just love that it bundles everything into 1 EXE.

Looks like FNXBasic file.open (filestream) always writes to the original app path (i.e. where the app resides) when read/writing files.

My text manipulating app is located in C:UTILS (included in Windows path).

I tried to force it to write to current path with these tests (both were unsuccessful).....
file.open("."+cmdofile$)
and
file.open("%cd%"+cmdofile$)

When I "CD " (C:) and run against a text file in C:, an interesting thing happened for the 2nd test:
>>Runtime error: Cannot create file "C:UTILS\%cd%list.txt"
(this is how I know its forcing the app path)

Any ideas? I cannot use the APPNAME$ FN because that returns exactly the above, is there something like a CURRPATH$ FN that I don`t know about? Basically, if I am in C: I want file.open to write in C:, if I am in C:My Documents, I want that directory, etc. etc.

Thanks in advance!

rdcoder1
Posts: 4
Joined: Mon Jul 23, 2012 4:01 pm

Uses app path instead of curr path for file.open

Post: # 911Post rdcoder1
Mon Jul 23, 2012 6:17 pm

After borrowing code from the member writing the mp3 player, I just used kernel32 call to get CurrPath.  This will work.  But I still think FNX Basic should default file.open to current working path (you can always modify that by leveraging the APPNAME$ FN and using just the path portion). Shouldn`t have to work so hard !

Declare GetCurrPath As "GetCurrentDirectoryA" of "kernel32"
  lBuffer as Integer
  lptstr as String byaddress
end declare

Dim CurrPath as String

GetCurrPath.lBuffer=255
GetCurrPath.execute
currPath=GetCurrPath.lptstr

PRINT "CURRPATH=`";CurrPath;"`"
WHILE INKEY$="":WEND

rdcoder1
Posts: 4
Joined: Mon Jul 23, 2012 4:01 pm

Uses app path instead of curr path for file.open

Post: # 912Post rdcoder1
Mon Jul 23, 2012 6:29 pm

Moral of the story, always include a fully-pathed filespec (even if you have to recreate it by calling GetCurrentDirectoryA), otherwise FNX Basic defaults to the install directory of your app.

If you fully-path the filespec, it uses that.

Marco
Site Admin
Posts: 246
Joined: Sat Sep 15, 2018 8:41 pm

Uses app path instead of curr path for file.open

Post: # 913Post Marco
Tue Jul 24, 2012 3:34 pm

have anibody tried dir$?
the current path is dir$("@").
I hope this will help.
best regards

Post Reply