Directory.GetFiles failure

  • Thread starter Thread starter Andrew Boswell
  • Start date Start date
A

Andrew Boswell

Hi,

On my Pocket PC, the call to Directory.GetFiles(folderPath) fails with "No
such directory" exception if folderPath ends in a space, even though the
folderPath is valid. It shows up OK in File Explorer.

DirectoryInfo.GetFiles also fails in the same way.

Any ideas for a workaround?

Thanks,
Andrew
 
GetFiles does work, are you sure you are giving it a valid directory?

For instance, try a Debug.Assert("SomeDirectory);
//now do the Directory.GetFiles("SomeDirectory"); //making sure the some
directory is the exact same thing.

You may even want to use a string or constant like sooo

string s = @"Storage Card\"

Debug.Assert(s);
string[] myFiles = Directory.GetFiles(s);

If you are using C#, make sure you use the @ and if not, make sure you
double escape the \\.

HTH,

Bill
 
Hi Bill,

Yes, all that is OK. My program works fine until I create a directory
(using file explorer) that has a space at the end of its name, then
GetFiles fails.

I've now written a workaround using native calls to FindFirstFile and
FindNextFile.

Thanks for your help.

Andrew



GetFiles does work, are you sure you are giving it a valid directory?

For instance, try a Debug.Assert("SomeDirectory);
//now do the Directory.GetFiles("SomeDirectory"); //making sure the
some directory is the exact same thing.

You may even want to use a string or constant like sooo

string s = @"Storage Card\"

Debug.Assert(s);
string[] myFiles = Directory.GetFiles(s);

If you are using C#, make sure you use the @ and if not, make sure you
double escape the \\.

HTH,

Bill
Andrew Boswell said:
Hi,

On my Pocket PC, the call to Directory.GetFiles(folderPath) fails
with "No such directory" exception if folderPath ends in a space,
even though the folderPath is valid. It shows up OK in File Explorer.

DirectoryInfo.GetFiles also fails in the same way.

Any ideas for a workaround?

Thanks,
Andrew
 
I've not tried it with Directories that end with a Space -- it will work
with "Storage Card" for instance. I'm going to give it a try though, b/c if
you end up with a Space at the end, it'd defintely make your program more
robust if you checked for a space if it will cause a problem. Definitely
something I want to check out.

Cheers,

Bill
Andrew Boswell said:
Hi Bill,

Yes, all that is OK. My program works fine until I create a directory
(using file explorer) that has a space at the end of its name, then
GetFiles fails.

I've now written a workaround using native calls to FindFirstFile and
FindNextFile.

Thanks for your help.

Andrew



GetFiles does work, are you sure you are giving it a valid directory?

For instance, try a Debug.Assert("SomeDirectory);
//now do the Directory.GetFiles("SomeDirectory"); //making sure the
some directory is the exact same thing.

You may even want to use a string or constant like sooo

string s = @"Storage Card\"

Debug.Assert(s);
string[] myFiles = Directory.GetFiles(s);

If you are using C#, make sure you use the @ and if not, make sure you
double escape the \\.

HTH,

Bill
Andrew Boswell said:
Hi,

On my Pocket PC, the call to Directory.GetFiles(folderPath) fails
with "No such directory" exception if folderPath ends in a space,
even though the folderPath is valid. It shows up OK in File Explorer.

DirectoryInfo.GetFiles also fails in the same way.

Any ideas for a workaround?

Thanks,
Andrew
 
Hi Bill,

Thanks. The problem is that if one of my users has a folder on their
Pocket Pc whose name ends with a space, I won't be able to process it
properly.

Thanks again,
Andrew
 
I noticed that if I try to create a directory with a trailing space using
File Explorer, it complains. Renaming a directory and putting a trailing
space at the end succeeds but seems to get cleared upon refresh. Something
is fishy there
 
Hi Alex,

Yes File Explorer works in the way that you describe, but Resco File
Explorer allows a blank space to be added at the end of a folder name
and it stays there.

Regards,
Andrew
 
Back
Top