Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am using Directory.Exists to test if a path is a dir or a file. I am sure it is one of the worst ways to do this.

 

Does anyone know of a better way to see if a path is a file or directory?

C#
Posted

See, the problem with doing it that way is that if the directory does not exist then things will get messed up because I am assuming that it is a file. I know I can use that and still work around it but I think there should be a better way.

 

I saw someone use bytes to determine if a path was a file or directory but I don't know if that is the best way either because if the file is empty then it will be 0 bytes just like the directory.

 

But I really don't know how they used bytes to determine that, so I may be completely wrong. I would think that a folder has some attribute that no file has and that is what should be tested for. But I don't know. Please help.

C#
Posted

Yes, that is exactly what I was talking about when I said,

"I know I can use that and still work around it but I think there should be a better way."

Maybe that is the best way. I don't know.

C#
Posted
I know there was a DLL you could link to in vb6 (IMGHLP.DLL i think) that had a fuction that would create a path if it didnt exist, how ever many subdirs, do you want this?

Phil Price�

Visual Studio .NET 2003 Enterprise Edition

Microsoft Student Partner 2004

Microsoft Redmond, EMEA Intern 2004

  • *Experts*
Posted

Two lines of code is one of the worst ways to do something? :p

 

I think it's pretty convenient considering that in VB6, before FileSystemObject, you had to try and open a file and trap for an error just to see if the file existed... :)

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
  • *Experts*
Posted

I thought there was an issue with Dir$ but I can't think of it offhand... (maybe not detecting system files or something similar?)

 

Glad you know about Dir$ - it's Awesome! Too bad it didn't include the ability to search through subdirectories recursively :)

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...