Author Topic: Question regarding the "\" in path...  (Read 2900 times)

0 Members and 1 Guest are viewing this topic.

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Question regarding the "\" in path...
« on: January 18, 2021, 11:01:34 am »
I am uncertain of the best practice for writing the "\" paths in filenames.

For example, when I have a sub folder, I usually use this, which works for me...

n& = _SNDOPEN("notes\note1.wav")

But I see often this way, with a ".\" added....

n& = _SNDOPEN(".\notes\note1.wav")

Does it differ on OS?  Which is the best way

- Dav

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Question regarding the "\" in path...
« Reply #1 on: January 18, 2021, 11:14:13 am »
.\ is simply the current directory, and ..\ is the directory above it.

(Unless you get to remapping drives and directories with symbolic links, and then things can get confusing.)

Generally  speaking, it shouldn’t matter a whole lot if you include that .\ in the file path, or not. 
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Question regarding the "\" in path...
« Reply #2 on: January 18, 2021, 11:18:05 am »
Thanks, @SMcNeill!  I just wanted to be sure - didn't know it linux people needed .\ in there or what. 

Also, I was thinking there was a QB64 command to remove the path from a given filename, but I can't find it it in the wiki.  Is there one?  I was almost certain there was...like doing this...

filname$ = "c:\files\notes\note.wav"
PRINT RemovePath$(filename$)

- Dav

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Question regarding the "\" in path...
« Reply #3 on: January 18, 2021, 11:23:00 am »
Use _INSTREV for that.  :)

Code: QB64: [Select]
  1.  fullPath$ = "C:\Documents and Settings\Administrator\Desktop\qb64\internal\c\libqb\os\win\libqb_1_2_000000000000.o"
  2. file$ = MID$(fullPath$, _INSTRREV(fullPath$, "\") + 1)
  3. PRINT file$

Or, for your function:

FUNCTION RemovePath$ (fullpath$)
     RemovePath$ = MID$(fullPath$, _INSTRREV(fullPath$, "\") + 1)
END FUNCTION
« Last Edit: January 18, 2021, 11:25:11 am by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Question regarding the "\" in path...
« Reply #4 on: January 18, 2021, 11:27:30 am »
Perfect!  Thanks again, Steve! 

- Dav

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Question regarding the "\" in path...
« Reply #5 on: January 18, 2021, 12:29:09 pm »
I find I have to tell QB64 where .ico and library files are with .\ for other files like image or sound, QB64 can find the files in same folder as the .exe without the need for .\   .h files are just assumed to be in same folder as QB64.exe

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Question regarding the "\" in path...
« Reply #6 on: January 18, 2021, 01:01:53 pm »
Thanks, @bplus.  I seem to remember now someone else said that to me about something I posted a while back, maybe the drum machine...

Btw, I'm getting ready to post another music app with sound files - but don't worry, I've renamed all the .ogg files to another extension.  So hopefully it won't crash for you if you decide to try it out.

- Dav