Sign in to follow this  
Followers 0
sak

File Path Split Switches

7 posts in this topic

#1 ·  Posted (edited)

Cut program name out of layer path.

You can format command to write applications with other commands.

Is a command that I own and design innovation.

Where mistakes help with :)

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("MustDeclareVars", 1)

Global $hForm, $name_Inp, $sel_Btn, $run_Btn
Global $sFile = @ProgramFilesDir & '\AutoIt3\Aut2Exe\Icons\SETUP09.ICO'
Global $nMsg, $tablefiles, $pathsplit, $program
Global $titledlg = 'Choose a program'
Global $optdlg = 'All files (*.*)'
Global $pathsplit, $strsplit[1], $strsplit[2], $strsplit[3], $strsplit[4]
Global $strsplit[5], $strsplit[6], $strsplit[7], $strsplit[8], $strsplit[9]

$hForm = GUICreate("File Path Split Switches Sample", 355, 140, -1, -1)
GUICtrlCreateLabel("Program name", 105, 16, 72, 17)
$name_Inp = GUICtrlCreateInput("", 32, 32, 209, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$sel_Btn = GUICtrlCreateButton("Browse", 248, 31, 75, 23, $WS_GROUP)
$run_Btn = GUICtrlCreateButton("Open", 136, 100, 75, 25, $WS_GROUP)
GUICtrlSetCursor(-1, 0)
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $sel_Btn
            $tablefiles = FileOpenDialog($titledlg, @DesktopDir & "/", $optdlg, 1 + 4, "", $hForm)
            If Not @error Then
                $pathsplit = StringSplit($tablefiles, '\')
                If StringInStr($pathsplit[1], '.') Then
                    $program = $pathsplit[1]
                ElseIf StringInStr($pathsplit[2], '.') Then
                    $program = $pathsplit[2]
                ElseIf StringInStr($pathsplit[3], '.') Then
                    $program = $pathsplit[3]
                ElseIf StringInStr($pathsplit[4], '.') Then
                    $program = $pathsplit[4]
                ElseIf StringInStr($pathsplit[5], '.') Then  ;pathsplit switches
                    $program = $pathsplit[5]
                ElseIf StringInStr($pathsplit[6], '.') Then
                    $program = $pathsplit[6]
                ElseIf StringInStr($pathsplit[7], '.') Then
                    $program = $pathsplit[7]
                ElseIf StringInStr($pathsplit[8], '.') Then
                    $program = $pathsplit[8]
                ElseIf StringInStr($pathsplit[9], '.') Then
                    $program = $pathsplit[9]
                EndIf
                    GUICtrlSetData($name_Inp, $program)
                    GUICtrlSetState($run_Btn, $GUI_ENABLE)
            EndIf
        Case $run_Btn
            ShellExecute($program, "", "", "open")
    EndSwitch
WEnd
Edited by sak

Share this post


Link to post
Share on other sites



I havent looked at what your script does.

You dont need to declare every element of an array

Global $pathsplit, $strsplit[1], $strsplit[2], $strsplit[3], $strsplit[4]

Global $strsplit[5], $strsplit[6], $strsplit[7], $strsplit[8], $strsplit[9]

This will do

$strsplit[9]


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Have a look at String Split... It will create an array with all "Splits" in it.

For example:

$sString = "This is a bit of text" ; Some text with spaces
$aArray = StringSplit($sString, " ") ; Split the text into an array containing every word, split by the "Space" character

You will get the following:

$aArray[0] = 6 ; The number of things it's split up into

$aArray[1] = "This"

$aArray[2] = "is"

$aArray[3] = "a"

$aArray[4] = "bit"

$aArray[5] = "of"

$aArray[6] = "text"

Mal

EDIT: Sorry, you've already used StringSplit. Your code is a bit wild.

What exactly are you asking??

Edited by Mallie99

Are you telling me something I need to know or something I want to know?

Share this post


Link to post
Share on other sites

If all you are trying to do is get the name from a path, you have 2 options:

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("MustDeclareVars", 1)

Global $hForm, $name_Inp, $sel_Btn, $run_Btn
Global $sFile = @ProgramFilesDir & '\AutoIt3\Aut2Exe\Icons\SETUP09.ICO'
Global $nMsg, $tablefiles, $pathsplit, $program
Global $titledlg = 'Choose a program'
Global $optdlg = 'All files (*.*)'
Global $pathsplit, $strsplit[8]

$hForm = GUICreate("File Path Split Switches Sample", 355, 140, -1, -1)
GUICtrlCreateLabel("Program name", 105, 16, 72, 17)
$name_Inp = GUICtrlCreateInput("", 32, 32, 209, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$sel_Btn = GUICtrlCreateButton("Browse", 248, 31, 75, 23, $WS_GROUP)
$run_Btn = GUICtrlCreateButton("Open", 136, 100, 75, 25, $WS_GROUP)
GUICtrlSetCursor(-1, 0)
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $sel_Btn
            $tablefiles = FileOpenDialog($titledlg, @DesktopDir & "/", $optdlg, 1 + 4, "", $hForm)
            If Not @error Then
                $pathsplit = StringSplit($tablefiles, '\')
                For $i = 1 to UBound($pathsplit) - 1
                    If StringInstr($pathsplit[$i], '.') Then
                          $program = $pathsplit[$i]
                    EndIf
                Next
                GUICtrlSetData($name_Inp, $program)
                GUICtrlSetState($run_Btn, $GUI_ENABLE)
            EndIf
        Case $run_Btn
            ShellExecute($program, "", "", "open")
    EndSwitch
WEnd

- or -

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("MustDeclareVars", 1)

Global $hForm, $name_Inp, $sel_Btn, $run_Btn
Global $sFile = @ProgramFilesDir & '\AutoIt3\Aut2Exe\Icons\SETUP09.ICO'
Global $nMsg, $tablefiles, $pathsplit, $program
Global $titledlg = 'Choose a program'
Global $optdlg = 'All files (*.*)'
Global $pathsplit, $strsplit[8]

$hForm = GUICreate("File Path Split Switches Sample", 355, 140, -1, -1)
GUICtrlCreateLabel("Program name", 105, 16, 72, 17)
$name_Inp = GUICtrlCreateInput("", 32, 32, 209, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
$sel_Btn = GUICtrlCreateButton("Browse", 248, 31, 75, 23, $WS_GROUP)
$run_Btn = GUICtrlCreateButton("Open", 136, 100, 75, 25, $WS_GROUP)
GUICtrlSetCursor(-1, 0)
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $sel_Btn
            $tablefiles = FileOpenDialog($titledlg, @DesktopDir & "/", $optdlg, 1 + 4, "", $hForm)
            If Not @error Then
                $pathsplit = StringSplit($tablefiles, '\')
                GUICtrlSetData($name_Inp, $pathsplit[$pathsplit[0]])
                GUICtrlSetState($run_Btn, $GUI_ENABLE)
            EndIf
        Case $run_Btn
            ShellExecute($program, "", "", "open")
    EndSwitch
WEnd

Are you telling me something I need to know or something I want to know?

Share this post


Link to post
Share on other sites

Check out _PathSplit() function in File.au3 :)

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Mallie99

Thank you very much

Your best really.

I have worn it to increase knowledge.

If not disturbing.

Ask that you help write this statement for me.

Command to import the file in the ListBox.

Double-file and select the item to open.

This command I can not write.

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