Jump to content
Macro Express Forums

Monitor folder for changes and then close program

Recommended Posts

I run a scheduled macro to launch a program that updates radio listings.


The program downloads data from the internet and creates a set of xml files in a known directory.


At the moment, I have no way of closing the program after it has done its thing. It just sits there until I close it.


All this usually happens when the PC is unattended, so the program awaits my arrival at the start of the working day.


I could just have a timer and tell it to go away after 10 minutes, say, but a better approach might be to monitor the folder, look for changes and then after a suitable interval, maybe a minute after the last change in the directory, to issue a close instruction.


I have looked for clues on how to go about this around here, in the help file, and in various examples. No luck.


Things like the "Repeat with Folder Example" look promising. But my rudimentary skills get not much further than that.


Any thoughts?

Link to comment
Share on other sites

Is the macro involved in the download process? Or is it essentially just a Program launch command? If for example it included commands every time there was a download (or these could be added, say by testing the web page's appearance), then the macro could reset a timer after every download. You could repeatedly test the time since the last reset. If it exceeded say 10 minutes, you'd issue a command to close the program.


Alternatively, if the macro is just a launcher, I reckon your idea would be fine. At appropriate intervals, say 1 minute, count the number of files in the folder. Then you have a choice of when to close the program:


1. If there's been no change in say 10 minutes, as you suggested.

2. If the count has reached a certain 'satisfactory' number that you can set (permanently or for each session).


Here's an example using the Repeat Folder command:


// The macro has launched the program, which is downloading XML files at unpredictable intervals and placing them into a folder C:\TEMP-XML.

Repeat Until %FileCount% Is Greater Than or Equal To "3"

Variable Set Integer %FileCount% to 0 // Reset before each folder loop.

Repeat with Folder C:\TEMP-XML

Variable Modify Integer %FileCount%: Increment

End Repeat

End Repeat

Text Box Display: Final message

// Commands to close the program.


And here's its code:

<COMMENT Value="The macro has launched the program, which is downloading XML files at unpredictable intervals and placing them into a folder C:\\TEMP-XML."/>
<REPEAT UNTIL Variable="%FileCount%" Condition="\x04" Value="3"/>
<VARIABLE SET INTEGER Option="\x00" Destination="%FileCount%" Value="0" _COMMENT="Reset before each folder loop."/>
<REPEAT WITH FOLDER Path="C:\\TEMP-XML" OnlyFiles="TRUE" Destination="%Filename%" FullPath="FALSE" ProcSubfolders="FALSE"/>
<VARIABLE MODIFY INTEGER Option="\x07" Destination="%FileCount%"/>
<TEXT BOX DISPLAY Title="Final message" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs16 FileCount = %FileCount%\r\n\\par \r\n\\par There are now at least 3 files in the folder.\\f1 \r\n\\par \r\n\\par \\f0 So the following commands would close the program and end the macro.\\f1 \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>
<COMMENT Value="Commands to close the program."/>


I tested this by adding (or copying) files to that folder while the macro was running.


Come back if not clear.



Terry, East Grinstead, UK

Link to comment
Share on other sites

When I have other programs generate or download files I choose “Wait For File Exists” and then “Wait For File Ready”. This assumes you know what the file names will be. If you don’t know the name do the same thing but nest it in a Repeat With Folder and possibly add a little wait time in between each one. You could even wait for something like 3 clean passes at 10 second waits. Several ways to do this. But simply getting a file list I don’t think would help because the file could still be busy downloading.



Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...