How to determine if it is a file or directory for an item under a folder? [modified]
-
Hi, How could you determine if a read item is a folder or a file in vb.net? For an instance I have read all the files under directory. At the same time there is a sub directory under the directory and I want to get its type. Thanks.
What a curious mind needs to discover knowledge is noting else than a pin-hole.
modified on Sunday, February 8, 2009 1:54 PM
-
Hi, How could you determine if a read item is a folder or a file in vb.net? For an instance I have read all the files under directory. At the same time there is a sub directory under the directory and I want to get its type. Thanks.
What a curious mind needs to discover knowledge is noting else than a pin-hole.
modified on Sunday, February 8, 2009 1:54 PM
Hi, File attributes would tell you. Here is a C# example, I don't have it in VB.NET:
FileInfo info=new FileInfo(fileName); attributes=info.Attributes; bool isFolder=(attributes & FileAttributes.Directory)!=0; ...
:)
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
-
Hi, How could you determine if a read item is a folder or a file in vb.net? For an instance I have read all the files under directory. At the same time there is a sub directory under the directory and I want to get its type. Thanks.
What a curious mind needs to discover knowledge is noting else than a pin-hole.
modified on Sunday, February 8, 2009 1:54 PM
If IO.File.Exists(Path) Then 'It is a file ElseIf IO.Directory.Exists(Path) Then 'It is a folder End If
-
Hi, File attributes would tell you. Here is a C# example, I don't have it in VB.NET:
FileInfo info=new FileInfo(fileName); attributes=info.Attributes; bool isFolder=(attributes & FileAttributes.Directory)!=0; ...
:)
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
The equivalent vb code is:
Dim info as New FileInfo(fileName) Dim isFolder As Boolean = info.Attributes And FileAttributes.Directory