Jump to content
sree161

How can i extract the location of selected file?

Recommended Posts

sree161

Hi all,
how can i get the location of selected file into a variable??

I tried all these but i didn't get desired output
$a = @ProgramFilesDir
$b = @ProgramsDir
  MsgBox(0, "", $a)
  MsgBox(0, "", $b)
 

Share this post


Link to post
Share on other sites
water

Please define "desired output".


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
sree161
22 minutes ago, water said:

Please define "desired output".

i am select a file a running a hot key which is set  before.
i need to assign the location of the selected document to a variable.
below is my complete program.

HotKeySet('h', 'HotKey1')

While 1
   sleep(5)
   WEnd


Func HotKey1()
  ConsoleWrite("n:" & @CRLF)
$a = @ProgramFilesDir
$b = @ProgramsDir
$f = @filedir ; i need to assign the location of selected file to this variable and display it.
  MsgBox(0, "", $a)
  MsgBox(0, "", $b)
   EndFunc

Share this post


Link to post
Share on other sites
water

Or do you mean you select a file in another program (e.g. Windows Explorer) and when the hotkey gets pressed you want to process this selected file?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

BTW: When posting code please use AutoIt code tags in the editor (the "<>" button). Makes your code much easier to read ;)
Example:

HotKeySet('h', 'HotKey1')

While 1
   Sleep(5)
WEnd

Func HotKey1()
  ConsoleWrite("n:" & @CRLF)
  $a = @ProgramFilesDir
  $b = @ProgramsDir
  $f = @filedir ; i need to assign the location of selected file to this variable and display it.
  MsgBox(0, "", $a)
  MsgBox(0, "", $b)
EndFunc

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
sree161
5 minutes ago, water said:

Or do you mean you select a file in another program (e.g. Windows Explorer) and when the hotkey gets pressed you want to process this selected file?

ya exactly...i am going to select a notepad file.
the location of notepad should be copied to that variable.

Share this post


Link to post
Share on other sites
sree161
1 minute ago, water said:

BTW: When posting code please use AutoIt code tags in the editor (the "<>" button). Makes your code much easier to read ;)
Example:

HotKeySet('h', 'HotKey1')

While 1
   Sleep(5)
WEnd

Func HotKey1()
  ConsoleWrite("n:" & @CRLF)
  $a = @ProgramFilesDir
  $b = @ProgramsDir
  $f = @filedir ; i need to assign the location of selected file to this variable and display it.
  MsgBox(0, "", $a)
  MsgBox(0, "", $b)
EndFunc

 

sure

 

Share this post


Link to post
Share on other sites
water

There are many examples on the forum on how to retrieve the selected file from Windows Explorer. One of them is:

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

Another BTW: When you reply to a post there is no need to quote the original post by clicking the Quote button. I know what I have written ;)
Just enter your reply at the end of the thread and click "Submit Reply".


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
sree161
1 hour ago, Jos said:

Which selected file? Do you mean the running script file?

Jos

no i am selecting a file from windows explorer...i need to pull the location of the file to a variable

Share this post


Link to post
Share on other sites
1957classic

Is this what you mean?

#include <MsgBoxConstants.au3>

$f = FileOpenDialog("Select File", "", "Text (*.txt)")
MsgBox($MB_SYSTEMMODAL, "File Location", $f, 5)

 

Share this post


Link to post
Share on other sites
water

No, he is looking for Windows Explorer to select files from.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
sree161

ya i need the script to get the location of the file when i select any file from any other location i.e. windows explorer
I used hotkey as posted in above comments

Share this post


Link to post
Share on other sites
mikell

Laziness is counterproductive   <_<
It took 2 minutes to find it using search, and 2 minutes more to make a runnable snippet  :idiot:

; https://www.autoitscript.com/forum/topic/144641-get-path-of-currently-selected-file-in-explorer/

#include <WinAPI.au3>

HotKeySet('h', 'GetExplorerSelection')

While 1
  Sleep(10)
Wend

Func GetExplorerSelection()
Local $saveClip = ""
Local $filesFolders = ""
Local $handle = _WinAPI_GetForegroundWindow()
Local $className = _WinAPI_GetClassName($handle)
If $className = "ExploreWClass" Or $className = "CabinetWClass" Then
  $saveClip = ClipGet()
  Send("^c")
  Sleep(50)
  $filesFolders = ClipGet()
  ClipPut($saveClip)
  Msgbox(0,"", $filesFolders)
EndIf
EndFunc

 

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

×