Jump to content

How To Detect When A Folder Is Opened ?


Recommended Posts

Valuater

Your script simply opens C:\Program Files.

What I need is to run a loop and every time I open any folder, to get a message which tells me which folder I opened.

Thanks

Tuk

do i have to hold your friggin hand

#include <GUIConstants.au3>

$folder = FileSelectFolder("Choose a folder.", "")

Run("explorer.exe " & $folder)
WinWaitActive("")
$window = WinGetTitle("")

Sleep(5000)

While 1

If WinActive($window) Then MsgBox(0,"Found", "The window is active" & @CRLF & $window, 2)

Sleep(15000)

WEnd

like some fries with that????

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

Well...either I don't understand the script or this is not what i need.

I have $folder="C:\Folder" and I want to run a script that will detect each time when $folder is opened.

Thanks

Tuk

Link to comment
Share on other sites

  • Moderators

Try this:

While 1
    $OpenExplorer = _GetOpenExplorer()
    If $OpenExplorer Then MsgBox(64, 'Info', $OpenExplorer)
    Sleep(10)
WEnd

Func _GetOpenExplorer()
    $OptTitleMode = Opt('WinTitleMatchMode', 4)
    Local $ExplorerTitle1 = WinGetTitle('Classname=ExploreWClass')
;Local $ExplorerTitle2 = WinGetTitle('Classname=CabinetWClass'); Check to see if this one is needed
    If WinExists($ExplorerTitle1) Then;Or WinExists($ExplorerTitle2) Then; Uncomment this line and the above if you want to use CabinetWClass also
        Opt('WinTitleMatchMode', $OptTitleMode)
        Return $ExplorerTitle1
    EndIf
    Opt('WinTitleMatchMode', $OptTitleMode)
    Return 0
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Try this:

While 1
    $OpenExplorer = _GetOpenExplorer()
    If $OpenExplorer Then MsgBox(64, 'Info', $OpenExplorer)
    Sleep(10)
WEnd

Func _GetOpenExplorer()
    $OptTitleMode = Opt('WinTitleMatchMode', 4)
    Local $ExplorerTitle1 = WinGetTitle('Classname=ExploreWClass')
;Local $ExplorerTitle2 = WinGetTitle('Classname=CabinetWClass'); Check to see if this one is needed
    If WinExists($ExplorerTitle1) Then;Or WinExists($ExplorerTitle2) Then; Uncomment this line and the above if you want to use CabinetWClass also
        Opt('WinTitleMatchMode', $OptTitleMode)
        Return $ExplorerTitle1
    EndIf
    Opt('WinTitleMatchMode', $OptTitleMode)
    Return 0
EndFunc
It does come with a toy!
Link to comment
Share on other sites

  • 2 weeks later...

While 1
    $OpenExplorer = _GetOpenExplorer()
    If $OpenExplorer Then MsgBox(64, 'Info', $OpenExplorer)
    Sleep(1000)
WEnd

Func _GetOpenExplorer()
    $OptTitleMode = Opt('WinTitleMatchMode', 4)
Local $ExplorerTitle2 = WinGetTitle('Classname=CabinetWClass')
    If WinExists($ExplorerTitle2) Then
        Opt('WinTitleMatchMode', $OptTitleMode)
        Return $ExplorerTitle2
    EndIf
    Opt('WinTitleMatchMode', $OptTitleMode)
    Return 0
EndFunc

This code works but it detect any folder opened.

I need to detect only a specific folder: C:\Folder

Where do I add this ?

Thank you

Tuk

Link to comment
Share on other sites

  • Moderators

If it's a specific file then do what Val has shown, if it is the folder specific, with other files inside, and you want any and all of them, you might try:

If StringInStr($OpenExplorer, 'C:\Folder') Then MsgBox(64, 'Info', $OpenExplorer)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I must be doing something wrong. Here are your both options as I used them but didn't work. Please help, thank you.

While 1
    $OpenExplorer = _GetOpenExplorer()
    If $OpenExplorer = "C:\Folder" Then MsgBox(64, 'Info', $OpenExplorer)
    Sleep(1000)
WEnd

Func _GetOpenExplorer()
    $OptTitleMode = Opt('WinTitleMatchMode', 4)
Local $ExplorerTitle2 = WinGetTitle('Classname=CabinetWClass')
    If WinExists($ExplorerTitle2) Then
        Opt('WinTitleMatchMode', $OptTitleMode)
        Return $ExplorerTitle2
    EndIf
    Opt('WinTitleMatchMode', $OptTitleMode)
    Return 0
EndFunc

While 1
    $OpenExplorer = _GetOpenExplorer()
     If StringInStr($OpenExplorer, 'C:\Folder') Then MsgBox(64, 'Info', $OpenExplorer)
    Sleep(1000)
WEnd

Func _GetOpenExplorer()
    $OptTitleMode = Opt('WinTitleMatchMode', 4)
Local $ExplorerTitle2 = WinGetTitle('Classname=CabinetWClass')
    If WinExists($ExplorerTitle2) Then
        Opt('WinTitleMatchMode', $OptTitleMode)
        Return $ExplorerTitle2
    EndIf
    Opt('WinTitleMatchMode', $OptTitleMode)
    Return 0
EndFunc
Link to comment
Share on other sites

  • Moderators

Ahh, your not going to get the directory name in that, it's simply picking up the title of the window, if the title of the window doesn't show the directory it is in, you won't get it.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

HotKeySet( "{Esc}", "exit_now" )

$folder = "C:\"

While 1
    If ControlGetText( "", "", 41477 ) = $folder Then
        MsgBox( 0, "ALERT", "Folder opened!" )
    EndIf
    
    Sleep( 250 )
WEnd

Func exit_now()
   Exit 
EndFunc

This code works for me. You might have to change 41477 to a dif control ID. Open my computer and launch the AutoItInfo Tool and get the control id of the edit field where it says my computer.

Edited by Don N

_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

Link to comment
Share on other sites

Don N

Yes ! Your code works perfect.

I am not expert so can you explain this "41477 to a dif control ID" issue ? -

Must I make the changes ?

Will your script work on all OS ?

Thank you very much

Tuk

Edited by Tukata
Link to comment
Share on other sites

The 41477 is the control id of the edit box that displays your current folder location when browising folders on your computer. Not sure if it will work on all os's as i can only test it on my copy here which is Win 2k SP4. Should work on all windows relaeses with the fact that you might have to change the contorl id, but other than that it is compatible with all windows releases.

This is what im talking about:

http://www.autoitscript.com/fileman/users/newLogic/control%20id%20example.gif

Hope that helps!

_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...