automatically open file?
Author
Discussion

Anatol

Original Poster:

1,392 posts

253 months

Monday 1st February 2010
quotequote all
Can anyone point me towards a way (Win7 or Vista) to monitor a folder for new files, and automatically open them in the appropriate software registered for their extension?

I've tried various folder monitoring shareware options, and they only seem to want to let me move/rename/delete files rather than open them.

TIA,

Tol

lestag

4,614 posts

295 months

Monday 1st February 2010
quotequote all
Anatol said:
Can anyone point me towards a way (Win7 or Vista) to monitor a folder for new files, and automatically open them in the appropriate software registered for their extension?

I've tried various folder monitoring shareware options, and they only seem to want to let me move/rename/delete files rather than open them.

TIA,

Tol
you could probably write something in powershell script http://technet.microsoft.com/en-us/scriptcenter/dd... if your that way inclined

Anatol

Original Poster:

1,392 posts

253 months

Monday 1st February 2010
quotequote all
I can *use* software. Coding it is beyond me, though wink

Thanks,

Tol

TonyToniTone

3,877 posts

268 months

Monday 1st February 2010
quotequote all
What are you trying to achieve - what if something nasty gets dumped in and opened?

Anatol

Original Poster:

1,392 posts

253 months

Monday 1st February 2010
quotequote all
It's for writing up bodywork quotes. The idea is to snap a digital photo of the damage, have an eye-fi card in the camera that drops the photos via our wi-fi network into a directory on a tablet pc, then have the photo open straight away in an image editing suite for annotation and adding to the quote document.

The file monitoring software I've found intended for monitoring network shares allows you to filter out or in all sorts of file-types, I'd be ignoring anything but jpgs.

Unfortunately I've not found a piece of software yet that will allow me to open the file, just move/rename/delete etc. frown

Tol

LordGrover

33,952 posts

231 months

Monday 1st February 2010
quotequote all
A bit of a faff, but you could bodge it with windows scheduler and batch files.
Create a batch file with something like IF EXIST *.JPG THEN PAINT.EXE *.JPG type thing. Get that to run every minute or so and include a command to move the file to another folder once it's been opened.
Haven't given it much thought so may be wrong but seems feasible at the mo...

lestag

4,614 posts

295 months

Monday 1st February 2010
quotequote all
So let me get this right
If file in directory open it
Once it has been edited, insert into document
save document
delete jpeg

sound right?

Anatol

Original Poster:

1,392 posts

253 months

Monday 1st February 2010
quotequote all
The response would need to be a few seconds max, rather than every few minutes.

The management of the file once it's been opened in the paint program wouldn't need to be automatic.

All it really needs to do is notice the new file pretty immediately and open it in the image editor.

Tol

amir_j

3,579 posts

220 months

Monday 1st February 2010
quotequote all
You need a program which runs as a background service & 'watches' the folder and then reacts accordingly.

If not needed urgent then drop me an pm and I'll knock one up for you.

TonyToniTone

3,877 posts

268 months

Monday 1st February 2010
quotequote all
You could give this a go, you would need change strMonitorFolder which is folder path using 4 slashes instead of one and the path to the application strAppPath

If you post up the path to the application and the folder I can modify it for you.

You need to save script as something.vbs


Dim strValidFileExt, strAppPath, strMonitorFolder
strValidFileExt = "JPG"
strAppPath = "c:\Windows\System32\mspaint.exe"
strMonitorFolder = "d:\\\\test\\\\new pics"

Set WshShell = WScript.CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")

Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM __InstanceOperationEvent WITHIN 1 WHERE Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
& "TargetInstance.GroupComponent='Win32_Directory.Name=""" & strMonitorFolder & """'")

Do While TRUE
Set objEventObject = colMonitoredEvents.NextEvent()
If objEventObject.Path_.Class = "__InstanceCreationEvent" Then CheckFile()
Loop

Sub CheckFile()
strFilePath = objEventObject.TargetInstance.PartComponent
arrFilePath = Split(strFilePath, "=")
strFilePath = arrFilePath(1)
strFilePath = Replace(strFilePath, "\\", "\")
strFilePath = Replace(strFilePath, Chr(34), "")
strFileExt = right(strFilePath, 3)
If UCase(strFileExt) = strValidFileExt Then WshShell.Run strAppPath & " " & """" & strFilePath & """"
End Sub

Anatol

Original Poster:

1,392 posts

253 months

Monday 1st February 2010
quotequote all
Wow, thank you for going to the trouble.

Will the .vbs just run and stay running when double-clicked?

Tol

TonyToniTone

3,877 posts

268 months

Monday 1st February 2010
quotequote all
No probs I just modified some scripts off the Scripting Guy the link gives you some details of whats going on.

It should keep running until the computer is shutdown or an error occurs, you can get it to start automatically when you log on by saving the following as something.reg and double click it.

Probably best to do this as script does not check to see if it already running.


Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
"MonitorFolder"="wscript d:\\test\\monitor.vbs"



TonyToniTone

3,877 posts

268 months

Monday 1st February 2010
quotequote all
removes registry value


Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
"MonitorFolder"=-