QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: MasterGy on December 09, 2020, 04:08:37 am

Title: What is my filename ?
Post by: MasterGy on December 09, 2020, 04:08:37 am
Hi ! can anyone tell me how to read out the filename of the program that is running? For example, I generate x.exe from x.bas. How does x.exe know that it is x.exe?
Title: Re: What is my filename ?
Post by: euklides on December 09, 2020, 04:22:32 am
Put a line in your program:

RunningProg$="Bond, my name is James Bond.exe"

(just an idea)

SEE ALSO:
https://www.qb64.org/forum/index.php?topic=1259.0
Title: Re: What is my filename ?
Post by: FellippeHeitor on December 09, 2020, 07:21:43 am
Code: QB64: [Select]
Title: Re: What is my filename ?
Post by: luke on December 09, 2020, 09:18:10 am
Minor nitpick: COMMAND$(0) could potentially also have a path component, in which case you'd want to remove it.

Or maybe you're only interested in seeing if the name matches a list of options, in which case you can just take the RIGHT$ of it.
Title: Re: What is my filename ?
Post by: euklides on December 09, 2020, 09:51:39 am
Very nice this "command$(0)"

So then file name is:
Filename$= RIGHT$(COMMAND$(0), LEN(COMMAND$(0)) - LEN(_CWD$) - 1)
Title: Re: What is my filename ?
Post by: SpriggsySpriggs on December 09, 2020, 09:54:20 am
@euklides @MasterGy
Or this:

Code: QB64: [Select]
  1. filename$ = MID$(COMMAND$(0), _INSTRREV(COMMAND$(0), "\") + 1)

Or, if in Linux or Mac:

Code: QB64: [Select]
  1. filename$ = MID$(COMMAND$(0), _INSTRREV(COMMAND$(0), "/") + 1)
Title: Re: What is my filename ?
Post by: MasterGy on December 10, 2020, 11:29:19 am
Thank you Felippe, and everybody ,that's exactly what I needed!