Directory Watcher
Bookmark and Share
 

Posted by Rahul in

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.

6 comments

Awesome!

From what I saw in the RSS 2 spec (http://cyber.law.harvard.edu/rss/rss.html), the URL for link is not restricted to non-File based URLs. I'd suggest this:

Look at your file url you are generating (log it to a file for example), and open one url in Firefox just to be SUPER sure you got the format right. file urls always confuse me with all the extra slashes. In other words - be sure your file url is proper.

If it is - file a bug against cffeed. cffeed throws errors normally when you pass in bad data, I know it does at the metadata level, so maybe for items it does not.

Oh dude - I think I see the problem. I believe you need to name the key rsslink, not link.

Try that and let me know.

FYI - I've complained publicly about this before. While I'm happy cffeed is in the language, it is NOT as easy as it should be. It really needs to be overhauled for CF9.

@raymond, The good or the bad point is that if I copy paste the url in the address bar the url works but doesn't work as a hyperlink. Also in IE the link works correctly.

I will try with rsslink instead of link.

For firefox I visiting http://kb.mozillazine.org/Firefox_:_Issues_:_Links_to_Local_Pages_Don't_Work
& updated security.checkloaduri setting but to no use

hi rahul could you please help me to write a similar code in order to move mails from the undeliver folder to the spool. please response as soon as possible at sachinchawla1231@yahoo.co.in

hi rahul could you please help me to write a similar code to move mails from undeliver folder to the spool folder. Please respond to my post asap at
sachinchawla1231@yahoo.co.in

I will be really grateful to you. thanks a lot

Post a Comment

About Me

My Photo
Rahul Narula

Application Architect Webteam@Adobe

View my complete profile

Subscribe via email

Enter your email address:

Live Traffic Map

  Powered by Blogger

Twitter

Archives