# how to run a batch file whenever a particular folder is opened



## jhl (Aug 13, 2008)

Is there a way to run a batch file whenever a folder is opened. For eg. Is it possible to run a file called "delbat" whenever a folder called "active" is opened ? 

thanks for any info on this

JHL


----------



## Squashman (Apr 4, 2003)

Autorun is only supported on Media like CD, DVD and I believe external USB or Firewire hard drives. You would probably need to search for a Third Party tool to do what you want. I have tried searching for one but have been unable to find one.


----------



## TheOutcaste (Aug 8, 2007)

I haven't found a tool for this either, but I didn't search too hard. Only way I can think of to do this would be with with one of the flavors of C, VB, or Windows Scripting. You would have to either constantly poll window titles to see if one for that folder opened up, or write a dll and hook it into explorer to check the calls to open windows. If it's not the folder you want, it simply passes it on. If it's yours, you start your batch.
I have no idea how to write something to hook in like that -- perhaps in the Software Development forum.
As far as polling, unless you have explorer set to show full path in the title, there could be many folders named active that would trigger your batch file. Plus, a lot of processor time polling every few seconds to see if a window opened.

HTH

Jerry


----------



## Squashman (Apr 4, 2003)

Might be able to do it with AutoIT or AutoHotKey. It think they both have the capability to wait for a Window to become active and then keep executing.


----------



## TheOutcaste (Aug 8, 2007)

I've seen AutoIT mentioned quite a bit, but never tried it. Downloaded, installed, and can confirm AutoIT will do this. Simple two line script if you just want it to run once.

I see I have a new language to learn now, if only I had the time...

Jerry


----------



## TheOutcaste (Aug 8, 2007)

Guess I could have posted the script:


```
WinWaitActive("cmdcons - Microsoft Internet Explorer")
RunWait(@COMSPEC & " /c c:\test.bat")
```
Runs test.bat when I open Explorer and click the cmdcons folder.

Jerry


----------



## jhl (Aug 13, 2008)

Thanks Outcaste and squashman for all your help- you guys are amazing--
One last question- is it possible to make a script that could automatically monitor the 'active" folder and if there are any changes within the "active" folder eg say the addition of a new folder within the "active" folder then it will run a batch file to del certain folders in the 'active folder"

thanks
JHL


----------



## Squashman (Apr 4, 2003)

There are plenty of 3rd party programs that can do that. That is all I could find when I was Google searching for you yesterday. Google search and you will find what you want.


----------

