Jump to content

Recommended Posts

Posted

So basically i know how to get the filename and the directory of said file, but here's the thing:

what i wanna do is make an GUICtrlInput where you can either paste the full path to the file or click a button that calls a _WinAPI_GetOpenFileName function with which the user can locate the file so the script can work with the $afile variable. so i know how to make the button work, but so far i can't figure out how to do this with the input control.

this is an extract of the code i have so far.

#include <StructureConstants.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

GUICreate("Form1", 204, 195, 309, 125)
$Input1 = GUICtrlCreateInput("Input1", 16, 16, 169, 21)
$Button1 = GUICtrlCreateButton("Locate", 16, 48, 169, 57, 0)
$Button2 = GUICtrlCreateButton("Open", 48, 128, 105, 25, 0)
GUISetState(@SW_SHOW)

Do
    $msg = GUIGetMsg()
    If $msg = $Button1 Then
        $afile = _WinAPI_GetOpenFileName("")
        GUICtrlSetData ($input1,$afile[1]) ;the directory path should be followed by the filename
    EndIf
    
    If $msg = $Button2 Then
        Run(GUICtrlRead($Input1)) ;now, how on earth can it know which is the directory and which is the filename?
    EndIf

Until $msg = $GUI_EVENT_CLOSE
Exit

there should be a way to put the $afile[1] variable followed by the $afile[2] in the same text, without getting that syntax error. anyone with an idea?

Posted

So basically i know how to get the filename and the directory of said file, but here's the thing:

what i wanna do is make an GUICtrlInput where you can either paste the full path to the file or click a button that calls a _WinAPI_GetOpenFileName function with which the user can locate the file so the script can work with the $afile variable. so i know how to make the button work, but so far i can't figure out how to do this with the input control.

this is an extract of the code i have so far.

#include <StructureConstants.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

GUICreate("Form1", 204, 195, 309, 125)
$Input1 = GUICtrlCreateInput("Input1", 16, 16, 169, 21)
$Button1 = GUICtrlCreateButton("Locate", 16, 48, 169, 57, 0)
$Button2 = GUICtrlCreateButton("Open", 48, 128, 105, 25, 0)
GUISetState(@SW_SHOW)

Do
    $msg = GUIGetMsg()
    If $msg = $Button1 Then
        $afile = _WinAPI_GetOpenFileName("")
        GUICtrlSetData ($input1,$afile[1]) ;the directory path should be followed by the filename
    EndIf
    
    If $msg = $Button2 Then
        Run(GUICtrlRead($Input1)) ;now, how on earth can it know which is the directory and which is the filename?
    EndIf

Until $msg = $GUI_EVENT_CLOSE
Exit

there should be a way to put the $afile[1] variable followed by the $afile[2] in the same text, without getting that syntax error. anyone with an idea?

This will work. $afile[1] contains path, $afile[2] .. $afile[n] contain selected file names

#include #include #include #include GUICreate("Form1", 204, 195, 309, 125)$Input1 = GUICtrlCreateInput("Input1", 16, 16, 169, 21)$Button1 = GUICtrlCreateButton("Locate", 16, 48, 169, 57, 0)$Button2 = GUICtrlCreateButton("Open", 48, 128, 105, 25, 0)GUISetState(@SW_SHOW)Do    $msg = GUIGetMsg()    If $msg = $Button1 Then        $afile = _WinAPI_GetOpenFileName("")        GUICtrlSetData ($input1,$afile[1] & "\" & $afile[2]) ;the directory path should be followed by the filename    EndIf    If $msg = $Button2 Then        Run(GUICtrlRead($Input1)) ;now, how on earth can it know which is the directory and which is the filename?    EndIfUntil $msg = $GUI_EVENT_CLOSEExit

Is there any particular reason why you aren't using AutoIt's built in FileOpenDialog function ?

 

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Posted (edited)

Is there any particular reason why you aren't using AutoIt's built in FileOpenDialog function ?

 

No reason, i just did'nt know about it since im fairly new to autoit.

but thank you for mentioning it, look:

#include <StructureConstants.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

GUICreate("Form1", 204, 195, 309, 125)
$Input1 = GUICtrlCreateInput("Input1", 16, 16, 169, 21)
$Button1 = GUICtrlCreateButton("Locate", 16, 48, 169, 57, 0)
$Button2 = GUICtrlCreateButton("Open", 48, 128, 105, 25, 0)
GUISetState(@SW_SHOW)

Do
    $msg = GUIGetMsg()
    If $msg = $Button1 Then
        $afile = FileOpenDialog("","", "All (*.*)")
        $afile=StringReplace($afile, "|", @CRLF)
        GUICtrlSetData ($input1,$afile)
    EndIf
    
    If $msg = $Button2 Then
        Run(GUICtrlRead($Input1))
    EndIf

Until $msg = $GUI_EVENT_CLOSE
Exit

thank you :)

Edited by Cybergon

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
  • Recently Browsing   0 members

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