Jump to content

File Path Split Switches


sak
 Share

Recommended Posts

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
Link to comment
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.

Link to comment
Share on other sites

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?

Link to comment
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?

Link to comment
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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...