aewarnick Posted March 27, 2003 Posted March 27, 2003 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? Quote C#
Moderators Robby Posted March 27, 2003 Moderators Posted March 27, 2003 Directory.Exists and File.Exists are fine to use, unless someone knows a better method. (I don't) Quote Visit...Bassic Software
philprice Posted March 27, 2003 Posted March 27, 2003 its fine for me. Quote Phil Price� Visual Studio .NET 2003 Enterprise Edition Microsoft Student Partner 2004 Microsoft Redmond, EMEA Intern 2004
aewarnick Posted March 27, 2003 Author Posted March 27, 2003 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. Quote C#
Moderators Robby Posted March 27, 2003 Moderators Posted March 27, 2003 hmm? Check if a directory exists with Directory.Exists then if true use File.Exists to see if the file exists, else create the directory, then create the file. Quote Visit...Bassic Software
aewarnick Posted March 27, 2003 Author Posted March 27, 2003 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. Quote C#
philprice Posted March 27, 2003 Posted March 27, 2003 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? Quote Phil Price� Visual Studio .NET 2003 Enterprise Edition Microsoft Student Partner 2004 Microsoft Redmond, EMEA Intern 2004
*Experts* Nerseus Posted March 27, 2003 *Experts* Posted March 27, 2003 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 Quote "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
*Gurus* divil Posted March 27, 2003 *Gurus* Posted March 27, 2003 Not true! You could use the Dir$ function :) Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
*Experts* Nerseus Posted March 27, 2003 *Experts* Posted March 27, 2003 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 Quote "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
aewarnick Posted March 27, 2003 Author Posted March 27, 2003 Ok, so I got my answer, there is no better way. I just thought that it was too primitive... Quote C#
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.