AutoHotkey Community

It is currently May 26th, 2012, 4:59 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 15 posts ] 
Author Message
PostPosted: February 22nd, 2009, 1:03 pm 
Offline

Joined: February 20th, 2009, 1:19 am
Posts: 12
Location: France
Hi,
Consider A_WScriptName equals to OneProblem.ahk
Then, try
Code:
  StringTrimRight, OutputVar, %A_WScriptName%, 4
 

to delete the extension in the result.
You get a formal error.
Else, I'm wrong, but How? :?:

Best regards
Dominique

_________________
dominique
www.sensagent.com


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 22nd, 2009, 1:19 pm 
Code:
A_WScriptName = OneProblem.ahk
StringTrimRight, OutputVar, A_WScriptName, 4
msgbox, %OutputVar%


When exactly are variable names enclosed in percent signs?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 22nd, 2009, 2:33 pm 
Offline

Joined: February 20th, 2009, 1:19 am
Posts: 12
Location: France
guest88a wrote:
Code:
A_WScriptName = OneProblem.ahk
StringTrimRight, OutputVar, A_WScriptName, 4
msgbox, %OutputVar%


When exactly are variable names enclosed in percent signs?



Oh... it does not work with or without percent signs...
If you do the same with A_username, it will work well.
Moreover, I patched the previous problem with that:

Code:

;msgbox %A_ScriptName%

 FileAppend, %A_ScriptName%, disaster
 FileRead, OutputVar, disaster
 StringTrimRight, monScript, OutputVar, 4
 FileDelete, disaster

;msgbox %monScript%



Have you an idea?[/quote]

_________________
dominique
www.sensagent.com


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 22nd, 2009, 3:09 pm 
dominique dutoit wrote:
guest88a wrote:
Code:
A_WScriptName = OneProblem.ahk
StringTrimRight, OutputVar, A_WScriptName, 4
msgbox, %OutputVar%


When exactly are variable names enclosed in percent signs?
Oh... it does not work with or without percent signs...

What do you mean it does not work. It does work, OutputVar contains the script name without the .ext!!

dominique dutoit wrote:
Code:
;msgbox %A_ScriptName%

 FileAppend, %A_ScriptName%, disaster
 FileRead, OutputVar, disaster
 StringTrimRight, monScript, OutputVar, 4
 FileDelete, disaster

;msgbox %monScript%


Have you an idea?
I have no idea what you are trying to accomplish with this code.

Code:
A_WScriptName = OneProblem.ahk
StringTrimRight, OutputVar, A_WScriptName, 4
msgbox, %OutputVar%

SetWorkingDir, %A_ScriptDir%

msgbox %A_ScriptName%

FileDelete, disaster
FileAppend, %A_ScriptName%, disaster
FileRead, OutputVar, disaster
StringTrimRight, monScript, OutputVar, 4
FileDelete, disaster
msgbox %monScript% ; monScript has name of script without extention


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 22nd, 2009, 3:34 pm 
Offline

Joined: February 20th, 2009, 1:19 am
Posts: 12
Location: France
I needed only to get the name of the current script without extension...
I called disaster the filename used to make the match.

In need because I 'm working of some attempt to generate thousands small scripts working a cyclic graph. For fun... and to learn AutoHotKey.

_________________
dominique
www.sensagent.com


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 22nd, 2009, 3:49 pm 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1934
Location: Germany
Then SplitPath is what you need.

To get filename without extension:
Code:
SplitPath, InputVar, , , , OutNameNoExt

Leave all the commas, to left out not needed variables. They are optional to get for example the extension only. But then you have the file name without extension AND without the full path, just file name. For the case you need the full path just without file extension, I wrote some time ago a function (also the output is temporary). And it works for any number of extension letters, not just 3.
Code:
MsgBox %A_ScriptFullPath%
MsgBox % Path_RemoveExtension(A_ScriptFullPath)

/*
    Path_RemoveExtension
    Removes the file extension from a path, if there is one.

    Returns the manipulated string.
   
    Leaves "ErrorLevel" unchanged.

    pPath
        String of path from which to remove the extension.

    Example:
        Path = foo.d@bar.net\bar.exe
        MsgBox % Path_RemoveExtension(Path)
    > foo.d@bar.net\bar
*/
Path_RemoveExtension(pPath)
{
    Local BackslashPos, DotPos
       
    If pPath
    {
        StringGetPos, BackslashPos, pPath, \, R
        BackslashPos++
        DotPos := InStr(pPath, ".", "", BackslashPos)
        If DotPos
        {
            DotPos--
            StringLeft, pPath, pPath, %DotPos%
        }
    }
    Return pPath
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 22nd, 2009, 3:56 pm 
Offline

Joined: February 20th, 2009, 1:19 am
Posts: 12
Location: France
It 's very nice! Thank you very much.

Dominique

_________________
dominique
www.sensagent.com


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 22nd, 2009, 4:05 pm 
Offline

Joined: February 20th, 2009, 1:19 am
Posts: 12
Location: France
:oops:
But it does not merge my need :

Splitpath needs :
---> Name of the variable containing the file name to be analyzed.

And I have not clearly this name. The process knows itself that it is runing: it's why I was interested by A_ScriptName; it was more elegant than create (and maintain) a name for each connexion (perhaps thousands) in the graph (what I try to avoid).

Thank you again

Dominique.

_________________
dominique
www.sensagent.com


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 22nd, 2009, 4:13 pm 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1934
Location: Germany
:?: I am not fully understand what you are trying to explain.

Code:
SplitPath, A_ScriptFullPath, , , , ScriptFullPathNoExt
MsgBox %ScriptNameNoExt%

???


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 22nd, 2009, 4:37 pm 
Offline

Joined: February 20th, 2009, 1:19 am
Posts: 12
Location: France
If I try you code,

Code:
SplitPath, A_ScriptFullPath, , , , ScriptFullPathNoExt
MsgBox %ScriptNameNoExt%

???[/quote]

I obtain an empty message box.
:cry:
My script containing your code was truc.ahk, and I expected to receive truc.ahk in the msgbox from the same code.

_________________
dominique
www.sensagent.com


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 22nd, 2009, 4:47 pm 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1934
Location: Germany
Why this does happen to me allways? sorry its a copy and paste error: :oops:

Code:
SplitPath, A_ScriptFullPath, , , , ScriptNameNoExt
MsgBox %ScriptNameNoExt%


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 22nd, 2009, 4:47 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Tuncay made a typo [edit: he corrected it already] is his variable name, should be the same:
Code:
SplitPath, A_ScriptFullPath, , , , ScriptFullNameNoExt
MsgBox %ScriptFullNameNoExt%
This displays
the name of the current script WITHOUT the extention AHK. No need to use SplitPath to display it WITH AHK as you can use A_ScriptName

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 22nd, 2009, 5:05 pm 
Offline

Joined: February 20th, 2009, 1:19 am
Posts: 12
Location: France
Tuncay wrote:
Why this does happen to me allways? sorry its a copy and paste error: :oops:

Code:
SplitPath, A_ScriptFullPath, , , , ScriptNameNoExt
MsgBox %ScriptNameNoExt%


:P Oh! It works nicely, exactly as I hoped it.
Nethertheless, perhaps it could be usefull to add a warning on
http://www.autohotkey.com/docs/Variables.htm about the fact that the variable A_ScriptName (The file name of the current script, without its path, e.g. MyScript.ahk.) could not be utilised simply with some functions, and a link to your post!

Thank you again!

_________________
dominique
www.sensagent.com


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 22nd, 2009, 5:25 pm 
Quote:
Nethertheless, perhaps it could be usefull to add a warning on
http://www.autohotkey.com/docs/Variables.htm about the fact that the variable A_ScriptName (The file name of the current script, without its path, e.g. MyScript.ahk.) could not be utilised simply with some functions, and a link to your post!

No!
You are simply ignoring that there is no problem at all.
Code:
StringTrimRight, OutputVar, A_ScriptName, 4
does work as well as
Code:
A_WScriptName = OneProblem.ahk
StringTrimRight, OutputVar, A_WScriptName, 4


I don“t know what error you made,
but as guest88a already showed, there is no problem with A_ScriptName or StringTrimRight


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 22nd, 2009, 5:40 pm 
Offline

Joined: February 20th, 2009, 1:19 am
Posts: 12
Location: France
:shock:
You are right, and... I dont know what error I made during a coupe of hours
Well. It 's the way to learn a bit. And to remenber. Thank you again.

_________________
dominique
www.sensagent.com


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, SifJar, SKAN and 44 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group