I need to query folder structure. In other words I need to be able to access directory structure by SQL. I'm thinking of that there should be some OLE DB provider or some ODBC driver for that purpose. My friend said to google "folder monitoring" but I can't find anything Now I'm doing in command prompt dir>somefile and importing resulted text file to the DB, but it's kind of "not real-time". I need to access it real time like explorer does. Is there a way? Thanks
Why do you need SQL specifically to query files and folders? What kind of query are you trying to make, and what are your performance requirements for it (for one thing, you should realize that query performance in the lack of indices will not depend on the query language).
I'm assuming you'll be storing information about the folder structure in your database as a hierarchy:
- ID
- ParentID
- ObjectName
For example, to store that fileA and fileB are under DirectoryD, you'd have three records: - 1, 1, root - 2, 1, DirectoryD - 3, 2, fileA - 4, 2, fileB
If that's the case, I recommend reading up on hierarchical db models:
You could try importing a .NET assembly into your database which contains the logic for querying the file-system, expose it as a user-defined-function and then call that function anytime you wanted to get the values from this directory in real-time.
Granted, I've only seen this done with scalar results from the .Net functions, but it should be possible to return table-values as well.
An easy C# example of doing file-system access can be found here, but if C# isn't your flavor, or you don't dabble in code at all then this won't be of any help.