Sign in to follow this  
Followers 0
Ephesian

Get File+Path from Notepad's Open File Dialog

5 posts in this topic

#1 ·  Posted

Greetings,

My apologies if this question is too easy, repetitive, or if this is the wrong place to ask. I'm a noob to AutoIT.

I'm working on a script that opens (for example) notepad followed by the Open File dialog ( Send ("^o") ). When a file is selected, and the Open button pressed, the file and it's path are returned to notepad. Is it possible to capture that Path\File information to my script?

If anyone could post some code, that would be helpful, but really all I need is for someone to point me to the some functions. I could look up their usage from the help file.

Thank You.

Share this post


Link to post
Share on other sites



#2 ·  Posted

Hi Ephesian,

3 hours ago, Ephesian said:

I'm working on a script that opens (for example) notepad followed by the Open File dialog ( Send ("^o") ).

What have you've got so far?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

@Ephesian,

Is this what you need?^_^

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    ; Run Notepad with the window maximized.
    Local $iPID = Run("notepad.exe", "", @SW_SHOWMAXIMIZED)

   ; Wait 2 seconds for the Notepad window to appear.
    WinWait("[CLASS:Notepad]", "", 2)
    Local $sFileOpenDialog = FileOpenDialog("Test", @WindowsDir & "\", "Text Document (*.txt)")
    If @error Then
        ; Display the error message.
        MsgBox($MB_SYSTEMMODAL, "", "No file was selected.")

        ; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder.
        FileChangeDir(@ScriptDir)
    Else
   MsgBox($MB_SYSTEMMODAL, "", "You chose the following file:" & @CRLF & $sFileOpenDialog)

   EndIf
   Send($sFileOpenDialog)
   sleep(2000)
   ProcessClose($iPID)
EndFunc   ;==>Example

 

Edited by KickStarter15

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

6 hours ago, KickStarter15 said:

@Ephesian,

Is this what you need?^_^

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    ; Run Notepad with the window maximized.
    Local $iPID = Run("notepad.exe", "", @SW_SHOWMAXIMIZED)

   ; Wait 2 seconds for the Notepad window to appear.
    WinWait("[CLASS:Notepad]", "", 2)
    Local $sFileOpenDialog = FileOpenDialog("Test", @WindowsDir & "\", "Text Document (*.txt)")
    If @error Then
        ; Display the error message.
        MsgBox($MB_SYSTEMMODAL, "", "No file was selected.")

        ; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder.
        FileChangeDir(@ScriptDir)
    Else
   MsgBox($MB_SYSTEMMODAL, "", "You chose the following file:" & @CRLF & $sFileOpenDialog)

   EndIf
   Send($sFileOpenDialog)
   sleep(2000)
   ProcessClose($iPID)
EndFunc   ;==>Example

Thank You, KickStarter15. The script works well, and answered several questions I had. But I should probably clarify. It's not really Notepad I'm using, but a software sampler called VSampler3.  The line in your example...

Local $sFileOpenDialog = FileOpenDialog("Test", @WindowsDir & "\", "Text Document (*.txt)")

... seems to open the script's own File Open dialog, not notepad's. It wasn't obvious to me at first until I tried it in VSampler3.

When I ran the script with VSampler3 a dialog does appear, but the selected file (.VS3) doesn't load into VSampler. What I'm trying to automate is the opening of VSampler3, Select the open file dialog to load a .VS3 file into the program , and obtain the selected file's path at the same time.

HOWEVER, I believe I found a way to do it using your method instead. Which I think would be better anyway. Rather than running VSampler first,:
1) Create an Open File dialog, 2) Select the file, 3) Obtain the path, 4) Use the Path in the target of VSampler3 to start the program with the VS3 file. I believe this might be a more efficient way of doing it actually. So Thank You for your ideas. The were of great help.

Thank You much

6 hours ago, KickStarter15 said:

 

 

Edited by Ephesian

Share this post


Link to post
Share on other sites

#5 ·  Posted

@Ephesian,

Well you can play with it and your Welcome.:D

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