Thanks Richard. I've repro'd this and forwarded onto a couple of guys on my 
team (we own System.IO). I'll report back to the group with their reply.

From: [email protected] [mailto:[email protected]] On 
Behalf Of Richard Carde
Sent: Friday, March 05, 2010 5:52 AM
To: ozdotnet
Subject: Problem with GetFiles() or me?

Back to a programming topic...(rare for me).

I've knocked up a small console application to process a folder structure with 
hundreds of thousands of small text files, read each file, strip off some 
headers and append the resulting data into a single large file.  The all worked 
fine until I needed to do it on a different path (mapped drive).

If I specify the path (first argument) as a drive letter (of a mapped drive) 
only, and that drive has a current working directory other than the root, it 
fails because GetFiles() returns an absolute path which is incorrect - it 
prepends the filenames with a \.

eg:

H:\>CD Z:\data_to_process
H:\>GetFilesTest.exe Z:
Processing file Z:\file1.txt
Processing file Z:\file2.txt
...

This isn't correct. While it correctly enumerates the files within the folder 
structure as specified, the path should be Z:file1.txt, etc.  Surely?

Tried with VS2008 & .Net 3.5 as well as VS2010 RC & .Net 4 - same behaviour.

A quick Google didn't turn up anything obvious.  So I'm thinking I've missed 
something in the documentation (which I must admit, I didn't read until it 
didn't work as expected) or am clueless about the vagaries of DOS 
working/current directories because this seems so simple.

----------8K-------------------8K-------------------8K----------
using System;
using System.IO;

namespace GetFilesTest
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Please specify a path");
                return;
            }

            // enumerate all files in the supplied path and subfolders
            string[] files = Directory.GetFiles(args[0], "cdr*.*", 
SearchOption.AllDirectories);

            Console.WriteLine(String.Format("Getting files from {0}", args[0]));

            // iterate over the files, displaying the full path
            foreach (string file in files)
            {
                Console.WriteLine(String.Format("Processing file {0}", file));
            }
        }
    }
}
----------8K-------------------8K-------------------8K----------

--
Richard Carde

Reply via email to