kcvinu Posted June 6, 2020 Share Posted June 6, 2020 Hi all, When my program starts, i need to get the currently opened folder path in windows explorer. How to get the path. Thanks in advance. :) Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only) Link to comment Share on other sites More sharing options...
faustf Posted June 6, 2020 Share Posted June 6, 2020 @scriptdir ? Link to comment Share on other sites More sharing options...
kcvinu Posted June 6, 2020 Author Share Posted June 6, 2020 @faustf Thanks for the reply, but no. @ScriptDir is not for my case. I will compile this program as an exe and when i run this program, what ever folder is open in explorer, i need to get it's path. Not the script directory. AFAIK, script directory is where the script/exe file resides. That's not what i want. Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only) Link to comment Share on other sites More sharing options...
Musashi Posted June 6, 2020 Share Posted June 6, 2020 1 hour ago, kcvinu said: When my program starts, i need to get the currently opened folder path in windows explorer. It is already an older thread, but maybe it is what you are looking for : windows-explorer-current-folder Since links get lost sometimes, here for the sake of convenience the related code in a spoiler. Spoiler expandcollapse popup#include <Array.au3> Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ComErrFunc") $aWinList=WinList("[REGEXPCLASS:^(Explore|Cabinet)WClass$]") For $i = 1 To $aWinList[0][0] ; Get base folder and selections $aSelection = _ExplorerWinGetSelectedItems($aWinList[$i][1]) ; Display as strings ConsoleWrite("Explorer Window: " & $aSelection[1] & " Selection(s)" & @CRLF) For $j = 2 To $aSelection[0] + 1 ConsoleWrite(@TAB & $aSelection[$j] & @CRLF) Next ; Display as array _ArrayDisplay($aSelection, "Explorer Instance #" & $i & " / " & $aWinList[$i][0]) Next ; ========================================================================================================================== ; Func _ObjectSHFolderViewFromWin($hWnd) ; ; Returns an 'ShellFolderView' Object for the given Window handle ; ; Author: Ascend4nt, based on code by KaFu, klaus.s ; ========================================================================================================================== Func _ObjectSHFolderViewFromWin($hWnd) If Not IsHWnd($hWnd) Then Return SetError(1,0,0) Local $oShell,$oShellWindows,$oIEObject,$oSHFolderView ; Shell Object $oShell=ObjCreate("Shell.Application") If Not IsObj($oShell) Then Return SetError(2,0,0) ; Get a 'ShellWindows Collection' object $oShellWindows = $oShell.Windows() If Not IsObj($oShellWindows) Then Return SetError(3,0,0) ; Iterate through the collection - each of type 'InternetExplorer' Object For $oIEObject In $oShellWindows If $oIEObject.HWND = $hWnd Then ; InternetExplorer->Document = ShellFolderView object $oSHFolderView=$oIEObject.Document If IsObj($oSHFolderView) Then Return $oSHFolderView Return SetError(4,0,0) EndIf Next Return SetError(-1,0,0) EndFunc ; ========================================================================================================================== ; Func _ExplorerWinGetSelectedItems($hWnd) ; ; ; Author: klaus.s, KaFu, Ascend4nt (consolidation & cleanup, Path name simplification) ; ========================================================================================================================== Func _ExplorerWinGetSelectedItems($hWnd) If Not IsHWnd($hWnd) Then Return SetError(1,0,'') Local $oSHFolderView Local $iSelectedItems,$iCounter=2,$aSelectedItems[2] = [0, ""] $oSHFolderView=_ObjectSHFolderViewFromWin($hWnd) If @error Then Return SetError(@error,0,'') ; SelectedItems = FolderItems Collection object->Count $iSelectedItems = $oSHFolderView.SelectedItems.Count Dim $aSelectedItems[$iSelectedItems+2] ; 2 extra -> 1 for count [0], 1 for Folder Path [1] $aSelectedItems[0]=$iSelectedItems ; ShellFolderView->Folder->Self as 'FolderItem'->Path $aSelectedItems[1]=$oSHFolderView.Folder.Self.Path ; ShellFolderView->SelectedItems = FolderItems Collection object $oSelectedFolderItems = $oSHFolderView.SelectedItems #cs ; For ALL items in an Explorer window (not just the selected ones): $oSelectedFolderItems = $oSHFolderView.Folder.Items ReDim $aSelectedItems[$oSelectedFolderItems.Count+2] #ce For $oFolderItem In $oSelectedFolderItems $aSelectedItems[$iCounter] = $oFolderItem.Path $iCounter += 1 Next Return SetExtended($iCounter-2,$aSelectedItems) EndFunc ;==>_ExplorerWinGetSelectedItems Func _ComErrFunc($oError) ConsoleWrite("COM Error occurred:" & @CRLF & _ "Number: " & @TAB & $oError.number & @CRLF & _ "Windescription:" & @TAB & $oError.windescription & @CRLF & _ "Description is: " & @TAB & $oError.description & @CRLF & _ "Source is: " & @TAB & $oError.source & @CRLF & _ "Helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ "Helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ "Lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ "Scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ "Retcode is: " & @TAB & $oError.retcode & @CRLF & @CRLF) EndFunc ;==>_ComErrFunc careca 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
MrCreatoR Posted June 6, 2020 Share Posted June 6, 2020 What if you have more than one folder open? What folder considered the one that you need? Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
argumentum Posted June 6, 2020 Share Posted June 6, 2020 ..the first found in the Z order ( my guess ) Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
kcvinu Posted June 6, 2020 Author Share Posted June 6, 2020 @Musashi, That Function will loop through all opened explorer windows. I just need only the last used/opened window. Anyways, it seems that things are little bit different than i expected. I thought that the folder path would be a simple property of Shell object.(like $Shell.ActiveFolder.Path). But this Function shows that it is not. Thanks for pointing me the right direction. @MrCreatoR, If there is more than one folder opened, then i need the last opened folder's address. Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only) Link to comment Share on other sites More sharing options...
argumentum Posted June 6, 2020 Share Posted June 6, 2020 ConsoleWrite(WinGetTitle("[CLASS:CabinetWClass]") & @CRLF) Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
kcvinu Posted June 6, 2020 Author Share Posted June 6, 2020 (edited) @argumentum, Thanks a lot. It will give the active explorer window's title. Now, i can get the hWnd of active explorer window and tweak Melba's KaFu's & Ascend4nt's solution which @Musashi pointed. Edited June 6, 2020 by kcvinu argumentum 1 Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only) Link to comment Share on other sites More sharing options...
kcvinu Posted June 6, 2020 Author Share Posted June 6, 2020 @argumentum, It seems that, i can achieve my goal only with your single line code if i turn on "Display full path in title bar" option in folder options. argumentum 1 Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only) Link to comment Share on other sites More sharing options...
KaFu Posted June 6, 2020 Share Posted June 6, 2020 18 minutes ago, kcvinu said: and tweak Melba's solution which @Musashi pointed. Not Melbas solution (this time🤣). kcvinu 1 OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Musashi Posted June 6, 2020 Share Posted June 6, 2020 1 hour ago, KaFu said: Not Melbas solution (this time🤣). No, surprisingly not . Normally I always name the author(s) when mentioning sources, so that acknowledgements go to the right address. Since they are listed in the function headers, I assumed that would be sufficient. For reasons of politeness among programmers, here is the corresponding addendum : Author : @Ascend4nt , based on code by @KaFu , klaus.s KaFu and kcvinu 2 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
kcvinu Posted June 6, 2020 Author Share Posted June 6, 2020 @KaFu Oops Sorry, my mistake. I only see that the code was posted by Melba. I didn't read the comments in code. My bad. I will edit my reply. Sorry for the mistake. KaFu 1 Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now