Sign in to follow this  
Followers 0
DssLexius

Get File name from $CmdLineRaw without path

12 posts in this topic

While 1
    $rep = GUIGetMsg()
    Switch $rep
        Case $GUI_EVENT_CLOSE
            Exit
        Case $B1
            Run($CmdLineRaw)
            Exit
        Case $B2; get the file name
            MsgBox(0, "File Name", "File name is: " & $CmdLineRaw, 50)
    EndSwitch
WEnd

on Case $B2 script shows a MessageBox with the FullPath and name of File but i only want to display the File Name.

can anyone tell me about it?

before compiling the message box looks like this

Posted Image

After compiling to exe the message box shows nothing.

Posted Image

after compiling it is not showing name or path.

i want to show a message box which will tell only file name and also after compiling it should work.

LOT OF THANXXXES IN ADVANCE FOR YOUR HELP

Share this post


Link to post
Share on other sites



That is because you have not passed it any parameters in the Command Line !

When it is compiled AutoIt3 does not include the exe name in $CmdLineRaw

Try passing it a parameter using Windows Run or from a Console window.

Share this post


Link to post
Share on other sites

$string = '/ErrorStdOut "C:\test\TestScript.au3"'
$result = StringRegExp($string,'/ErrorStdOut\h+"(?:.*\\)?(.*)"',3)
Msgbox(0,"File Name","File name is: " & $result[0])

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

That is because you have not passed it any parameters in the Command Line !

When it is compiled AutoIt3 does not include the exe name in $CmdLineRaw

Try passing it a parameter using Windows Run or from a Console window.

thanks for the information.

$string = '/ErrorStdOut "C:\test\TestScript.au3"'
$result = StringRegExp($string,'/ErrorStdOut\h+"(?:.*\\)?(.*)"',3)
Msgbox(0,"File Name","File name is: " & $result[0])
Thanks for your code example. it's working fine now but it is still showing *.au3 file name after compiling. Edited by DssLexius

Share this post


Link to post
Share on other sites

i renamed the script to "CompiledProgram.au3" and compiled it.

after compiling the file name was "CompiledProgram.EXE" but on running it and clicking the button for message box it shows

Posted Image

:) script name is "CompiledProgram.exe" but it is still showing "TestScript.AU3"

can you correct it? or tell me what is the problem?

thanks a lot for your help to me.

Share this post


Link to post
Share on other sites

i renamed the script to "CompiledProgram.au3" and compiled it.

after compiling the file name was "CompiledProgram.EXE" but on running it and clicking the button for message box it shows

Posted Image

:) script name is "CompiledProgram.exe" but it is still showing "TestScript.AU3"

can you correct it? or tell me what is the problem?

thanks a lot for your help to me.

It looks like you blindly followed what weaponx told you. Remove his $String = line and then in the next line replace $string with $CmdLineRaw.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

All you need is this (I think):

If @compiled Then
   $FileName = @AutoItExe
   $iSlashPos = StringInStr($FileName, "\", 1, -1)
   If $iSlashPos > 0 Then $FileName = StringMid($FileName, $iSlashPos+1)
Else
   $FileName = @ScriptName
EndIf

MsgBox(0, "File Name", "File name is: " & $FileName, 50)

Share this post


Link to post
Share on other sites

All you need is this (I think):

If @compiled Then
   $FileName = @AutoItExe
   $iSlashPos = StringInStr($FileName, "\", 1, -1)
   If $iSlashPos > 0 Then $FileName = StringMid($FileName, $iSlashPos+1)
Else
   $FileName = @ScriptName
EndIf

MsgBox(0, "File Name", "File name is: " & $FileName, 50)
no i don't need this but thanks for you effort.

ok, i changed the code to this

While 1
    $rep = GUIGetMsg()
    Switch $rep
        Case $GUI_EVENT_CLOSE
            Exit
        Case $B1
            Run($CmdLineRaw)
            Exit
        Case $B2; get the file name
            $result = StringRegExp($CmdLineRaw,'/ErrorStdOut\h+"(?:.*\\)?(.*)"',3)
            Msgbox(0,"File Name","File name is: " & $result[0])
    EndSwitch
WEnd

but now it is giving this error:

Line -1:

Error: Subscript used with non-Array variable.

Share this post


Link to post
Share on other sites

Looks like StringRegExp() is getting an error.

Use this to see if StringRegExp() is getting an error:

While 1
    $rep = GUIGetMsg()
    Switch $rep
        Case $GUI_EVENT_CLOSE
            Exit
        Case $B1
            Run($CmdLineRaw)
            Exit
        Case $B2; get the file name
            $result = StringRegExp($CmdLineRaw,'/ErrorStdOut\h+"(?:.*\\)?(.*)"',3)
            If @error Then
                MsgBox(0, "test", "Error in StringRegExp()")
            Else
                Msgbox(0,"File Name","File name is: " & $result[0])
            EndIf
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites

Looks like StringRegExp() is getting an error.

Use this to see if StringRegExp() is getting an error:

While 1
    $rep = GUIGetMsg()
    Switch $rep
        Case $GUI_EVENT_CLOSE
            Exit
        Case $B1
            Run($CmdLineRaw)
            Exit
        Case $B2; get the file name
            $result = StringRegExp($CmdLineRaw,'/ErrorStdOut\h+"(?:.*\\)?(.*)"',3)
            If @error Then
                MsgBox(0, "test", "Error in StringRegExp()")
            Else
                Msgbox(0,"File Name","File name is: " & $result[0])
            EndIf
    EndSwitch
WEnd
ok, on trying this i am getting the following Error:

Posted Image

i added a line to get error number and with error number:

Posted Image

from the HelpFile about StringRegExp() errors:

Flag = 3 or 4 :

@Error Meaning

0 Array is valid.

1 Array is invalid. No matches.

2 Bad pattern, array is invalid. @Extended = offset of error in pattern.

can anyone help me to Resolve this?

Share this post


Link to post
Share on other sites

ok, on trying this i am getting the following Error:

Posted Image

i added a line to get error number and with error number:

Posted Image

from the HelpFile about StringRegExp() errors:

Flag = 3 or 4 :

@Error Meaning

0 Array is valid.

1 Array is invalid. No matches.

2 Bad pattern, array is invalid. @Extended = offset of error in pattern.

can anyone help me to Resolve this?

The StringREgExp is trying to match whatever comes after the last '\' character. If you don't have such a character in your parameters then that is why it fails. What are the parameters you are using?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

This is like communication over broken phone.

While 1
    $rep = GUIGetMsg()
    Switch $rep
        Case $GUI_EVENT_CLOSE
            Exit
        Case $B1
            Run($CmdLineRaw)
            Exit
        Case $B2; get the file name
            MsgBox(0, "File Name", "File name is: " & $CmdLineRaw, 50)
    EndSwitch
WEnd

on Case $B2 script shows a MessageBox with the FullPath and name of File but i only want to display the File Name.

can anyone tell me about it?

before compiling the message box looks like this

Posted Image

After compiling to exe the message box shows nothing.

Posted Image

after compiling it is not showing name or path.

i want to show a message box which will tell only file name and also after compiling it should work.

LOT OF THANXXXES IN ADVANCE FOR YOUR HELP

And that is exactly as it should be.

DaRam gave you all the answers you need, just read again (both his posts).

Read and try to understand, you'll see. It's all there.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0