tags:

views:

240

answers:

2

I'm trying to query the filesystem on a remote machine in order to get a list of file names in a specific directory.

Until now, I'm using the DirectoryInfo class in .NET. Something like this:

DirectoryInfo dir = new DirectoryInfo("c:\dir");
FileInfo[] files = dir.GetFiles("*.*");

But this query answers in an average of 20/30 seconds. Sometimes is lasts 50 seconds. That's to much. I want to optimize it. After some googling I've found that this could be done with WMI. But I'm not getting any success. I'm getting errors like "RPC server is unavailable" and I don't have access to change permissions or services in that machine.

Does anyone have any other idea?

A: 

You won't get any faster performance going across the network. You're combatting network latency, as well as anything that's happening to affect the performance on the remote machine (eg., disk io or high CPU usage).

Ken White
Unless it's a very large folder that would only account a few seconds: certainly less than 10 and not the 20-30+ he's complaining about. If it's a very large folder, then maybe.
Joel Coehoorn
The problem isn't in the network. like Joel said it's a very large folder and the machine is overloaded by a web service that returns the file names for a specific directory. I want to optimize the web service (it isn't in the same machine where the files are) when it queries the file system
Rodrigo Guerreiro
A: 

What about a WCF service running on the remote machine? That could take a request, then return a bulk data transfer object with an object graph of the folders and files.

I appreciate this might not fit with your architecture, but if you have control over both environments it might be a way forward?

Neil Barnwell
that's a good ideia but i don't have control in the remote machine :(
Rodrigo Guerreiro
Fair enough, it was a bit left-field anyway. Might be useful for someone browsing StackOverflow in the future, anyway.
Neil Barnwell