Jump to content
Sign in to follow this  
hiepxuan2008

How to Open Folder and Select File

Recommended Posts

hiepxuan2008

Hi, I'm build my soft.

And I catch a trouble with Open Folder and Select File

It likes Internet Download Manager

Posted Image

Posted Image

Like The Picture, When I open folder, It will open folder and select file.

Other forums also discuss about it, but I don't have knowledge for C#

http://stackoverflow.com/questions/334630/open-folder-and-select-the-file

So, How to Open And Select File with autoit

Edited by hiepxuan2008

Share this post


Link to post
Share on other sites
water

Is it just me that can't see the images you included?

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
MuchTex

Is it just me that can't see the images you included?

You don't see the posted image? Just kidding I'm pretty sure that's everyone.

Share this post


Link to post
Share on other sites
hiepxuan2008

Are you talking about the built in internet download manager that is within Internet Explorer?

Reply: I don't mean built IDM, I just give example about open folder and select file.

Example: I have a path of a file "C:hiepit.jpg" and I want to open the folder with a file is selected

Is it just me that can't see the images you included?

Oh! I have just reupdated it!

The first Pic, I choose a file and click Open Folder

Posted Image

The second picture is a result, Explore open Folder contain its file, and select its file.

Posted Image

Edited by hiepxuan2008

Share this post


Link to post
Share on other sites
water

Looks like you need function FileOpenDialog.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
hiepxuan2008

@Water: Can you give me a code for it.

(Code open folder and select it, if we have path 'C:/hiepit')

Edited by hiepxuan2008

Share this post


Link to post
Share on other sites
water

You want to select the folder or a file in the folder?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
hiepxuan2008

You want to select the folder or a file in the folder?

A file.

$PATH='C:/hiepit.jpg'

Share this post


Link to post
Share on other sites
hiepxuan2008

We had a PATH 'C:hiepit.jpg'

And we write

The program auto open folder contain its file and select its file. Not we choose the path for it

( I gave example about IDM)

Edited by hiepxuan2008

Share this post


Link to post
Share on other sites
water

Something like:

$sSelectedFile = FileOpenDialog("Please select a file", "C:\", "Images (*.jpg)", 3, "hiepit.jpg")
MsgBox(0, "Selected file", $sSelectedFile)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
hiepxuan2008

Something like:

$sSelectedFile = FileOpenDialog("Please select a file", "C:\", "Images (*.jpg)", 3, "hiepit.jpg")
MsgBox(0, "Selected file", $sSelectedFile)

This code mean we choose path for it.

It's not my mind: I gave example about IDM , Have you ever used IDM.

Edited by hiepxuan2008

Share this post


Link to post
Share on other sites
water

I don't fully get it. You want to select the file in the list of files (that's how I understand your screenshot). What should the user or your script do then?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
KaFu
hiepxuan2008

_WinAPI_ShellOpenFolderAndSelectItems(). is my mind.

Thanks you! KaFu

Share this post


Link to post
Share on other sites
KaFu
hiepxuan2008

I'm trying make it short, because I only use a function _WinAPI_ShellOpenFolderAndSelectItems

Share this post


Link to post
Share on other sites
hiepxuan2008

Wow, I'm sucess . THanks all. It can do work independently

_WinAPI_ShellOpenFolderAndSelectItems('C:\hiepit.jpg')

Func _WinAPI_ShellOpenFolderAndSelectItems($sPath, $aNames = 0, $iStart = 0, $iEnd = -1, $iFlags = 0)

Local $PIDL, $Ret, $tPtr = 0, $Count = 0, $Obj = 0

$sPath = _WinAPI_PathRemoveBackslash(_WinAPI_PathSearchAndQualify($sPath))
If IsArray($aNames) Then
If ($sPath) And (Not _WinAPI_PathIsDirectory($sPath)) Then
Return SetError(1, 0, 0)
EndIf
EndIf
$PIDL = _WinAPI_ShellILCreateFromPath($sPath)
If @error Then
Return SetError(1, 0, 0)
EndIf
If IsArray($aNames) Then
If $iStart < 0 Then
$iStart = 0
EndIf
If ($iEnd < 0) Or ($iEnd > UBound($aNames) - 1) Then
$iEnd = UBound($aNames) - 1
EndIf
$tPtr = DllStructCreate('ptr[' & ($iEnd - $iStart + 1) & ']')
If @error Then
; Nothing
Else
For $i = $iStart To $iEnd
$Count += 1
If $aNames[$i] Then
DllStructSetData($tPtr, 1, _WinAPI_ShellILCreateFromPath($sPath & '\' & $aNames[$i]), $Count)
Else
DllStructSetData($tPtr, 1, 0, $Count)
EndIf
Next
EndIf
EndIf
If _WinAPI_CoInitialize() Then
$Obj = 1
EndIf
$Ret = DllCall('shell32.dll', 'uint', 'SHOpenFolderAndSelectItems', 'ptr', $PIDL, 'uint', $Count, 'ptr', DllStructGetPtr($tPtr), 'dword', $iFlags)
If @error Then
$Ret = 0
Else
If $Ret[0] Then
$Ret = $Ret[0]
EndIf
EndIf
If $Obj Then
_WinAPI_CoUninitialize()
EndIf
_WinAPI_CoTaskMemFree($PIDL)
For $i = 1 To $Count
$PIDL = DllStructGetData($tPtr, $i)
If $PIDL Then
_WinAPI_CoTaskMemFree($PIDL)
EndIf
Next
If Not IsArray($Ret) Then
Return SetError(1, $Ret, 0)
EndIf
Return 1
EndFunc ;==>_WinAPI_ShellOpenFolderAndSelectItems


Func _WinAPI_PathSearchAndQualify($sPath, $fExists = 0)

Local $Ret = DllCall('shlwapi.dll', 'int', 'PathSearchAndQualifyW', 'wstr', $sPath, 'wstr', '', 'int', 4096)

If (@error) Or (Not $Ret[0]) Then
Return SetError(1, 0, '')
EndIf
If ($fExists) And (Not FileExists($Ret[2])) Then
Return SetError(2, 0, '')
EndIf
Return $Ret[2]
EndFunc ;==>_WinAPI_PathSearchAndQualify


Func _WinAPI_PathRemoveBackslash($sPath)

Local $Ret = DllCall('shlwapi.dll', 'ptr', 'PathRemoveBackslashW', 'wstr', $sPath)

If @error Then
Return SetError(1, 0, '')
Else
If Not $Ret[0] Then
Return $sPath
EndIf
EndIf
Return $Ret[1]
EndFunc ;==>_WinAPI_PathRemoveBackslash

Func _WinAPI_ShellILCreateFromPath($sPath)

Local $Ret = DllCall('shell32.dll', 'uint', 'SHILCreateFromPath', 'wstr', $sPath, 'ptr*', 0, 'dword*', 0)

If @error Then
Return SetError(1, 0, 0)
Else
If $Ret[0] Then
Return SetError(1, $Ret[0], 0)
EndIf
EndIf
Return $Ret[2]
EndFunc ;==>_WinAPI_ShellILCreateFromPath


Func _WinAPI_CoInitialize($iFlags = 0)

Local $Ret = DllCall('ole32.dll', 'uint', 'CoInitializeEx', 'ptr', 0, 'dword', $iFlags)

If @error Then
Return SetError(1, 0, 0)
Else
If $Ret[0] Then
Return SetError(1, $Ret[0], 0)
EndIf
EndIf
Return 1
EndFunc ;==>_WinAPI_CoInitialize

Func _WinAPI_CoUninitialize()
DllCall('ole32.dll', 'none', 'CoUninitialize')
If @error Then
Return SetError(1, 0, 0)
EndIf
Return 1
EndFunc ;==>_WinAPI_CoUninitialize

Func _WinAPI_CoTaskMemFree($pMemory)
DllCall('ole32.dll', 'none', 'CoTaskMemFree', 'ptr', $pMemory)
If @error Then
Return SetError(1, 0, 0)
EndIf
Return 1
EndFunc ;==>_WinAPI_CoTaskMemFree




Func _WinAPI_PathIsDirectory($sPath)

Local $Ret = DllCall('shlwapi.dll', 'int', 'PathIsDirectoryW', 'wstr', $sPath)

If @error Then
Return SetError(1, 0, 0)
EndIf
Return $Ret[0]
EndFunc   ;==>_WinAPI_PathIsDirectory
Edited by hiepxuan2008

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  

×