all groups > dotnet compact framework > january 2007 >
You're in the

dotnet compact framework

group:

Directory.Exist - Weird problem



Re: Directory.Exist - Weird problem ctacke/
1/17/2007 9:07:22 AM
dotnet compact framework: 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
--



[quoted text, click to view]

Re: Directory.Exist - Weird problem Paul G. Tobey [eMVP]
1/17/2007 9:33:37 AM
Maybe one device doesn't have the space in the directory name between
"storage" and "card"...

Paul T.

[quoted text, click to view]

Re: Directory.Exist - Weird problem Paul G. Tobey [eMVP]
1/17/2007 11:18:55 AM
File system driver.

Paul T.

[quoted text, click to view]

Re: Directory.Exist - Weird problem Peter Foot [MVP]
1/17/2007 1:10:43 PM
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

--
Peter Foot
Device Application Development MVP
www.peterfoot.net | www.inthehand.com

[quoted text, click to view]
Directory.Exist - Weird problem Thore Berntsen
1/17/2007 1:35:17 PM
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



Re: Directory.Exist - Weird problem Thore Berntsen
1/17/2007 2:45:02 PM
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

[quoted text, click to view]

Re: Directory.Exist - Weird problem Thore Berntsen
1/17/2007 6:57:42 PM
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
[quoted text, click to view]

AddThis Social Bookmark Button