views:

147

answers:

2

I currently have a filesystem path I would like to index into a SQL database. I need to access the data so that I can do queries against files based on modified times, or partial names, or many other items.

Is there a way to somehow sync a filesystem to a database automatically, or even access a filesystem in a sql-like interface, without having to crawl through folders recursively?

I was checking the Microsoft Sync Framework 2.0, since it supports SQL databases now, however it doesn't appear to support syncing files to databases.

I'm sure other vendors do something similar, such as Microsoft for the database of files in Media Center, or programs like TVersity storing a database of the files as well.

+1  A: 

You don't mention a programming language but here is how I would do it and I think it's the way most media apps maintaining a library do it (although they might be writter in different languages and use the win32 api).

Using .net to get your initial data I would once recursively scan the directory and then add all information to the database. Then I would run a service using a FileSystemWatcher object to be notified about changes and process the events accordingly.

olle
My only issue with using a FileSystemWatcher is if the service isn't running (ie machine reboot) while file activity happens on this share. Then I have to re-scan everything.I might have to go this route if nothing else works. It's the first thought I was coming up with as well.
Matt Andreko
A: 

It sounds like what you want is Windows Search. (or the Windows 7 Library feature if you're feeling bleeding edge).

Ultimately though something has to crawl the disk to pull the info out, whether it's you or a third party service.

As an aside SQL may not be the best tool for that particular job, depending on exactly what you want to search for. Tree structures are notoriously tricky to represent in relational databases efficiently - your searches could get quite expensive!

Marc
I'm not sure Windows Search will do what I want. I'm going to give it a shot, but accessing it programatically doesn't look super easy.
Matt Andreko