_OpenFile Dialog in same folder as exe - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Utilities (https://qb64phoenix.com/forum/forumdisplay.php?fid=8) +---- Thread: _OpenFile Dialog in same folder as exe (/showthread.php?tid=1233) Pages:
1
2
|
RE: _OpenFile Dialog in same folder as exe - DSMan195276 - 12-05-2022 I wouldn't recommend relying on `Command$(0)`, it's unreliable for this as it may have a relative path such as `./foobar/qb64pe.exe`. Stripping off the exe in that case will give you the path "./foobar", which will be treated relative to your current CWD and likely give you the wrong result since it's not absolute. The best way to handle this would be saving the contents of `_CWD$` as soon as the program starts, since we always fill that with the location of the executable (discovered by OS-specific means other than `Command$(0)`). If you're finding that `_CWD$` is unreliable for some reason at the start of the program then that sounds like a bug, but it really shouldn't be as it's fairly straight forward in what it does. I'd be curious to hear what behavior you're seeing where it's wrong. RE: _OpenFile Dialog in same folder as exe - bplus - 12-05-2022 (12-05-2022, 03:12 AM)SMcNeill Wrote: Personally, I'd go this way: Yes makes sense to have slash ready for other file work. RE: _OpenFile Dialog in same folder as exe - bplus - 12-05-2022 (12-05-2022, 03:48 AM)DSMan195276 Wrote: I wouldn't recommend relying on `Command$(0)`, it's unreliable for this as it may have a relative path such as `./foobar/qb64pe.exe`. Stripping off the exe in that case will give you the path "./foobar", which will be treated relative to your current CWD and likely give you the wrong result since it's not absolute. OK it's possible I got confused which where I was. I have a nightmare jungle of GUI versions in a couple of places and loading files from IDE I sometimes mess up path... I will switch back to _Cwd$ if that is the one most likely to return the full or absolute path and try and pay more attention when using _OpenFileDialog$ Thanks for the an under-the-hood tip That slash thing still could be handy. RE: _OpenFile Dialog in same folder as exe - SMcNeill - 12-05-2022 Just remember to use _CWD$ at the start of the program, and to save the result to a non-changing variable. If you navigate to different folders, your _CWD$ isn't going to be the same one that you started in. Code: (Select All) $If WIN Then RE: _OpenFile Dialog in same folder as exe - Pete - 12-05-2022 Brings back memories. Back in the ol' days we had to use a SHELL DIR to get the current folder. I used CHDIR a lot, so I always did the SHELL call then set a variable DIM SHARED OrigDir to the original directory the exe was running in. Pete RE: _OpenFile Dialog in same folder as exe - bplus - 12-05-2022 (12-05-2022, 05:54 AM)SMcNeill Wrote: Just remember to use _CWD$ at the start of the program, and to save the result to a non-changing variable. If you navigate to different folders, your _CWD$ isn't going to be the same one that you started in. (12-05-2022, 10:47 AM)Pete Wrote: Brings back memories. Back in the ol' days we had to use a SHELL DIR to get the current folder. I used CHDIR a lot, so I always did the SHELL call then set a variable DIM SHARED OrigDir to the original directory the exe was running in. Yes 2 thumbs up from one thread! I think I will call slash, OSslash$, and it probably is better as fixed string. Actually my OP code would work better for code where I was pasting on forward slash or backslash?... (geez those are worse than left or right!) I was building pathed filenames with Linux slash because Windows didn't care so OSslash$ will have to be new code. Very good! Pete, it does remind me of the shell like program I made back in DOS days. I remember having something rewriting a batch file as you use the batch file. Pretty cool stuff to modify a program (this more a script I suppose) as you Run it. RE: _OpenFile Dialog in same folder as exe - Pete - 12-05-2022 Batch files were a great tool. I made a few, but I had some friends who created them frequently, who created them frequently. Is there an ECHO in here? Pete |