Author Topic: What is my filename ?  (Read 3483 times)

0 Members and 1 Guest are viewing this topic.

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
What is my filename ?
« 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?

Offline euklides

  • Forum Regular
  • Posts: 128
    • View Profile
Re: What is my filename ?
« Reply #1 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
« Last Edit: December 09, 2020, 04:29:16 am by euklides »
Why not yes ?

FellippeHeitor

  • Guest
Re: What is my filename ?
« Reply #2 on: December 09, 2020, 07:21:43 am »
Code: QB64: [Select]

Offline luke

  • Administrator
  • Seasoned Forum Regular
  • Posts: 324
    • View Profile
Re: What is my filename ?
« Reply #3 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.

Offline euklides

  • Forum Regular
  • Posts: 128
    • View Profile
Re: What is my filename ?
« Reply #4 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)
Why not yes ?

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: What is my filename ?
« Reply #5 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)
« Last Edit: December 09, 2020, 09:57:36 am by SpriggsySpriggs »
Shuwatch!

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: What is my filename ?
« Reply #6 on: December 10, 2020, 11:29:19 am »
Thank you Felippe, and everybody ,that's exactly what I needed!