Directory Watcher
Posted by Rahul in ColdFusion
A few months back during our internal DevSummit at Adobe, India an engineer demo a slick little utility that sits in the system tray and monitors a directory for updates. It notifies the user of any update to the configured directory. The light weight utility also had a RSS feed that yours can subscribe to provided you have it enabled.
On the lines of this utility standalone executable, I thought doing this in ColdFusion was a cake walk. Using the Directory Watcher event gateway provided with ColdFusion I built a RSS feed using <CFFEED> for all the music I have on my machine. The feed will be refreshed everytime I added more music, so my friends subscribed to my music feed get updated.
<cfcomponent>
<cffunction name="onAdd" output="no">
<cfargument name="CFEvent" type="struct" required="yes">
<cfdirectory directory="c:\music\" recurse="yes" name="music" filter="*.mp3">
<cfquery name="mymusic" dbtype="query">
select name,size,directory, DATELASTMODIFIED from music where type='File' order by DATELASTMODIFIED desc
</cfquery>
<cfscript>
// Create the feed data structure and amymusic the metadata.
MovieStruct = { link="http://rnarula03",title="Music", description="Music directory for Rahul", pubDate="#now()#", version="rss_2.0", item=arraynew(1) };
/ Add the feed items.
for(i=1; i <= mymusic.recordcount; i++)
{
MovieStruct.item[i] = StructNew();
MovieStruct.item[i].description = StructNew();
S = numberformat(mymusic.size[i]/(1024*1024));
link = replace(mymusic.directory[i],"c:\music","")&"\"&mymusic.name[i];
MovieStruct.item[i].description.value = "Movie "& mymusic.name[i] &" (" & S &" MB)";
MovieStruct.item[i].description.value = MovieStruct.item[i].description.value & "<br><br>Download at: \\servername\music" &link;
//MovieStruct.item[i].link ="file://///rnarula03/music/"&link;
MovieStruct.item[i].pubDate = GetHttpTimeString(mymusic.DATELASTMODIFIED[i]) ;
MovieStruct.item[i].title = replace(Rereplacenocase(mymusic.name[i],"\.mp3$",""),"."," ","ALL");
}
</cfscript>
<!--- Generate the feed and save it to a file and variable. --->
<cffeed action="create" name="#MovieStruct#" outputfile="c:\wwwroot\music.xml" overwrite="true">
</cffunction>
</cfcomponent>
This will publish the complete list of music files in my folder, which is also shared to facilitate easy download. The only issue I am having is the network file share link doesn't work from Firefox due to some reason. Still investigating on the same. Also the network link (like file://///servername/share) is not treated as a valid link in RSS & it doesn't appear as link on the fed item. If anyone has any idea on the same, please let me know about it.

