Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Get the Base name of the running script


  • Please log in to reply
2 replies to this topic
Tasman
  • Members
  • 21 posts
  • Last active: Sep 04 2006 08:33 PM
  • Joined: 20 May 2006
This is a very simple function that returns the base name (ie. the name of the script without the extention) for use by for instance ini scripts.
This way if the name of the main script or exe is changed a corresponding ini file can be created/used, avoiding errors.

Just in case anybody is wondering why I am posting small trivialities like this, it's that I am in the process of writing a minimalist shell based on AHK
and these are functions used in it and I thought they might come in handy by others.

I'll be posting more stuff in the next few days just do a search for Tasman (runbox replacement, volume replacement etc., things normally handled by explorer)

dbase := getscriptname() ; get the base name of this program without the extension
ini = %A_ScriptDir%\%dbase%.ini ; and create the name of, for instance an ini file to use with this script.

MsgBox, %ini%

getscriptname(){
	dbase = %A_ScriptName%
	Length := StrLen(A_ScriptName)-4
	StringLeft, dbase, A_ScriptName, Length
	return %dbase%
}

I have a working version of the shell running on my own computer but its not ready for the primelight yet. You need to be carefull with shells, if you mess up you might not be able to get windows running again.
A lot of testing remains before I post all of it.

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Dear Tasman, :)

This is a very simple function that returns the base name (ie. the name of the script without the extention) for use by for instance ini scripts.
This way if the name of the main script or exe is changed a corresponding ini file can be created/used, avoiding errors.


Nice idea.. However it can be shortened to

GetScriptName(){ 
StringTrimRight,Name, A_ScriptName, 4
Return Name
}


... and I feel this is better version :

GetScriptName(){ 
SplitPath, A_ScriptFullPath,,,,Name, 
Return Name
}

I'll be posting more stuff in the next few days just do a search for Tasman (runbox replacement, volume replacement etc., things normally handled by explorer)

I have a working version of the shell running on my own computer but its not ready for the primelight yet. You need to be carefull with shells, if you mess up you might not be able to get windows running again.
A lot of testing remains before I post all of it.


Sounds interesting! .. Will await it.

Regards, :)
kWo4Lk1.png

Tasman
  • Members
  • 21 posts
  • Last active: Sep 04 2006 08:33 PM
  • Joined: 20 May 2006
Thanks for the tip Goyyah
Love it when I can do the same with less code.
Changed my other submission accordingly (a simple runbox).