Directory.Exist - Weird problem

  • Thread starter Thread starter Thore Berntsen
  • Start date Start date
T

Thore Berntsen

I have a CF 2.0 program where I have code like this:

if (Directory.Exists("\\Storage Card\\Import\\) ...

This works on all devices I tried yet except for the ViewSonic V.37. On this
device the call returns false even if the directory exists.

If I write
if (Directory.Exists("\\Storage Card\\Import) ... (Without trailing
backslash) it works fine.

It is not releated to the storage card. I have tested that.

Ideas anyone?

Thore Berntsen
 
Normally a folder path would be expressed without the trailing slash
character, so you should stick to the format of the second example.
Path.GetDirectoryName() will return you a valid directory from a path.
On a related note, you shouldn't hard code your paths to "Storage Card"
since this varies between devices e.g. CF Card, SD Card etc. An easy way to
retrieve card names is to get all the directories off the root folder which
have the Temporary attribute. e.g.

DirectoryInfo rootDir = new DirectoryInfo("\\");

//add all removable drives
foreach (DirectoryInfo di in rootDir.GetDirectories())
{
//if directory and temporary
if ((di.Attributes & System.IO.FileAttributes.Temporary) ==
System.IO.FileAttributes.Temporary)
{
//folder is a removable card
}
}

Peter
 
Thank's but that doesn't really explain the differense in behavior from
device to device.

The hardcoding of paths was just for the example. I never do this in a
application.

Thore
 
Not sure what explanation you're after. The devices behave differently
because somewhere down in their FSD, the work a little differently. The
point Peter is making is that folder names should not have the trailing
slash and your search should strip them out with a Path.GetDirectoryName
call to ensure this.

Don't think of this as a bug where one device doesn't work - think of it as
a bug where the others do work when they shouldn't.


--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
 
Maybe one device doesn't have the space in the directory name between
"storage" and "card"...

Paul T.
 
Thank you all!

The Path.GetDirectoryName solved my problem.
By the way, what is FSD short for?

"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> wrote in message news:[email protected]...
 
File system driver.

Paul T.

Thore Berntsen said:
Thank you all!

The Path.GetDirectoryName solved my problem.
By the way, what is FSD short for?

"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> wrote in message news:[email protected]...
Maybe one device doesn't have the space in the directory name between
"storage" and "card"...

Paul T.
 
Back
Top