Sign in to follow this  
Followers 0
Farrukh

Selecting and opening a file from Explorer or similar tool

8 posts in this topic

Hi Experts.

I'm just a newbie and going to start my learning afterward. But I need a quick help:

Can we pick selected file name and path in Windows explorer and pass this info to Notepad or Notepad++ to open that file?

I might try that with Q-Dir (A beautiful, multi-panel/multi-tab Free Windows Explorer alternative) (http://www.softwareok.com/?seite=Freeware/Q-Dir).

I know, I can make association with file extensions, but actually I wanted to use Notepad++ or Universal File Viewer as a default File Viewer for most my files.

Here is a bit detailed elaboration by me:)

If you ever used Total Commander, Free Commander, or Ultra Explorer, they got a built-in File Viewer which further supports Addins to extend its usability and formats. That can be invoked using F3 key.

I was using Ultra Explorer, but now I've got x64 bit machine and there is no version of UE for x64 bit windows (or might be in development stages there).

On Windows 7 x64, I have only Q-Dir which is Quad Panel and Tab supported and fully x64bit enabled. The only deficiency is to use a file viewer similarly in Free Commander using some shortcut key. Although, there is a good option i.e. Run (still in beta phase) to execute other tools like NP++, but not with any hot key....

So, I thought, using AutoIt scripts, this functionality can be added to any Windows Application, Right?

Your help would be a great guide towards learning using a specific target.

Thank a lot :)

Share this post


Link to post
Share on other sites



Not certain I get what you are wanting.

Is this it.

$s_file = FileOpenDialog("Select a file",@ScriptDir & "\","All Files (*.*)")
If @error Then
    MsgBox(4096,"","No File(s) chosen or bad filter")
    Exit
EndIf

Run("Notepad.exe " & $s_file)

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

Hi John

Thanks for your reply :).

In windows explorer, if you click on a file that would be selected and I want to pick its name and path and then using a hot key, like Ctrl+F3:

Run("Notepad.exe " & $s_file)

Not certain I get what you are wanting.

Is this it.

$s_file = FileOpenDialog("Select a file",@ScriptDir & "\","All Files (*.*)")
If @error Then
    MsgBox(4096,"","No File(s) chosen or bad filter")
    Exit
EndIf

Run("Notepad.exe " & $s_file)

Share this post


Link to post
Share on other sites

I see, well since i'm in a jolly mood, heres some crude code that does the job.

HotKeySet("{F2}", "_open")
HotKeySet("{ESC}","_exit")

While 1
    Sleep(100)
WEnd

Func _open()
    ClipPut("")
    Do
        Send("^c")
        Sleep(100)
    Until ClipGet() <> ""
    $str = ClipGet()
    ClipPut("")
    $afiles = StringSplit($str,@LF,3)
    If IsArray($afiles) Then
        For $i = 0 To UBound($afiles)-1
            Run("Notepad.exe " & $afiles[$i])
        Next
    Else
        MsgBox(0,"Error","No files selected")
    EndIf
EndFunc   ;==>_open

Func _exit()
    Exit
EndFunc

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

Hey John,

That's Great

GOD bless you with more happiness and jolly life. :)

Yes, it is working much like I want it, even more than that, because I just tried that in Q-Dir and Windows Explorer and working awesomely.

Thank a lot buddy....

I see, well since i'm in a jolly mood, heres some crude code that does the job.

HotKeySet("{F2}", "_open")
HotKeySet("{ESC}","_exit")

While 1
    Sleep(100)
WEnd

Func _open()
    ClipPut("")
    Do
        Send("^c")
        Sleep(100)
    Until ClipGet() <> ""
    $str = ClipGet()
    ClipPut("")
    $afiles = StringSplit($str,@LF,3)
    If IsArray($afiles) Then
        For $i = 0 To UBound($afiles)-1
            Run("Notepad.exe " & $afiles[$i])
        Next
    Else
        MsgBox(0,"Error","No files selected")
    EndIf
EndFunc   ;==>_open

Func _exit()
    Exit
EndFunc

Share this post


Link to post
Share on other sites

Hi John,

Just one more question:

Can we make it to work all the time, i.e. without using a Hot Shortcut Key.

For instance, whenever I click a file in Explorer, it copies its name to Clipboard?

I'm actually just trying to get rid of pressing F3 again and again for each file..

Thanks a lot

:)

Right back at you buddy.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Well I suppose so.

#include <Misc.au3>

HotKeySet("{ESC}", "_Exit")

$hwnd = WinActivate("window title"); Get a handle to your window, else you could wind up in a loop pickle.

While 1
    If WinActive($hwnd) Then
        If _IsPressed("01") Then
            Sleep(100)
            Send("{F2}")
            Sleep(100) ; to short delay will cause problems
            Send("^a")
            _open()
        EndIf
    EndIf
    Sleep(10)
WEnd

Func _open()
    ClipPut("")
    Do
        Send("^c")
        Sleep(100)
    Until ClipGet() <> ""
    $str = ClipGet()
    ClipPut("")
    $afiles = StringSplit($str, @LF, 3)
    If IsArray($afiles) Then
        For $i = 0 To UBound($afiles) - 1
            Run("Notepad.exe " & $afiles[$i])
        Next
    Else
        MsgBox(0, "Error", "No files selected")
    EndIf
EndFunc   ;==>_open

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Edit: slight alter code.

Edited by JohnOne

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

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