I want a method basically that tells me if a path is a file or directory, or
any other possibilities.
What do i need to do? I'm hoping I dont have to manually determine all these
things with Exists()
for FileInfo and DirectoryInfo. If I do have to do that, is a directory also
a file?
Seems like something there may be built in support for but I cant find it
-simon
public PathType GetPathType (string path) {
....
determine if path is directory or file
....
}
enum PathType {
Directory,
File,
VirtualDirectory,
InvalidPath,
FileSystemUnavailable,
NonExistent
} 4 55323
Try this
// get the file attributes for file or directory
FileAttributes attr = File.GetAttributes(@"c:\Temp");
//detect whether its a directory or file
if((attr & FileAttributes.Directory) == FileAttributes.Directory)
MessageBox.Show("Its a directory");
else
MessageBox.Show("Its a file");
Shak
"Andy Gilman" <an*********@hotmail.com> wrote in message
news:OL**************@TK2MSFTNGP12.phx.gbl... I want a method basically that tells me if a path is a file or directory,
or any other possibilities. What do i need to do? I'm hoping I dont have to manually determine all
these things with Exists() for FileInfo and DirectoryInfo. If I do have to do that, is a directory
also a file? Seems like something there may be built in support for but I cant find it
-simon
public PathType GetPathType (string path) { ... determine if path is directory or file ... }
enum PathType { Directory, File, VirtualDirectory, InvalidPath, FileSystemUnavailable, NonExistent }
thanks. so a directory IS a 'file' as well as a directory
"Shakir Hussain" <sh**@fakedomain.com> wrote in message
news:u7**************@tk2msftngp13.phx.gbl... Try this
// get the file attributes for file or directory FileAttributes attr = File.GetAttributes(@"c:\Temp");
//detect whether its a directory or file if((attr & FileAttributes.Directory) == FileAttributes.Directory) MessageBox.Show("Its a directory"); else MessageBox.Show("Its a file");
Shak "Andy Gilman" <an*********@hotmail.com> wrote in message news:OL**************@TK2MSFTNGP12.phx.gbl... I want a method basically that tells me if a path is a file or
directory, or any other possibilities. What do i need to do? I'm hoping I dont have to manually determine all these things with Exists() for FileInfo and DirectoryInfo. If I do have to do that, is a directory also a file? Seems like something there may be built in support for but I cant find
it -simon
public PathType GetPathType (string path) { ... determine if path is directory or file ... }
enum PathType { Directory, File, VirtualDirectory, InvalidPath, FileSystemUnavailable, NonExistent }
One way to think about is like a treeview. It is a node in a tree. A node
can be of type directory or file. If a file, then the node is a leaf node
that can not contain children. If a directory, the node can contain
children. All nodes have base properties like attributes, name, etc. hth
--
William Stacey, MVP
"Andy Gilman" <an*********@hotmail.com> wrote in message
news:uU**************@TK2MSFTNGP12.phx.gbl... thanks. so a directory IS a 'file' as well as a directory
"Shakir Hussain" <sh**@fakedomain.com> wrote in message news:u7**************@tk2msftngp13.phx.gbl... Try this
// get the file attributes for file or directory FileAttributes attr = File.GetAttributes(@"c:\Temp");
//detect whether its a directory or file if((attr & FileAttributes.Directory) == FileAttributes.Directory) MessageBox.Show("Its a directory"); else MessageBox.Show("Its a file");
Shak "Andy Gilman" <an*********@hotmail.com> wrote in message news:OL**************@TK2MSFTNGP12.phx.gbl... I want a method basically that tells me if a path is a file or directory, or any other possibilities. What do i need to do? I'm hoping I dont have to manually determine all these things with Exists() for FileInfo and DirectoryInfo. If I do have to do that, is a
directory also a file? Seems like something there may be built in support for but I cant find it -simon
public PathType GetPathType (string path) { ... determine if path is directory or file ... }
enum PathType { Directory, File, VirtualDirectory, InvalidPath, FileSystemUnavailable, NonExistent }
how is it possible that i get this exception when getting attributes for a
file
Message "Could not find file \"E:\\Documents and
Settings\\Administrator\\My Documents\\testdoc.doc\"." string
StackTrace " at System.IO.__Error.WinIOError(Int32 errorCode, String
str)\r\n at System.IO.File.GetAttributes(String path)\r\n at
TSECommon.ExtractSystemIcon.GetIcon(String strPath, Boolean bSmall) in
E:\\Documents and Settings\\Administrator\\My Documents\\Visual Studio
Projects\\StudyEdge\\TSECommon\\ExtractSystemIcon. cs:line 107" string
The documentation states that I should get -1 back if the file doesnt exist
!
-simon
"Shakir Hussain" <sh**@fakedomain.com> wrote in message
news:u7**************@tk2msftngp13.phx.gbl... Try this
// get the file attributes for file or directory FileAttributes attr = File.GetAttributes(@"c:\Temp");
//detect whether its a directory or file if((attr & FileAttributes.Directory) == FileAttributes.Directory) MessageBox.Show("Its a directory"); else MessageBox.Show("Its a file");
Shak "Andy Gilman" <an*********@hotmail.com> wrote in message news:OL**************@TK2MSFTNGP12.phx.gbl... I want a method basically that tells me if a path is a file or
directory, or any other possibilities. What do i need to do? I'm hoping I dont have to manually determine all these things with Exists() for FileInfo and DirectoryInfo. If I do have to do that, is a directory also a file? Seems like something there may be built in support for but I cant find
it -simon
public PathType GetPathType (string path) { ... determine if path is directory or file ... }
enum PathType { Directory, File, VirtualDirectory, InvalidPath, FileSystemUnavailable, NonExistent }
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Pernell Williams |
last post by:
Hi all:
I am new to Python, and this is my first post (and it won't be my last!), so
HELLO EVERYONE!! I am attempting to use "xreadlines", an outer loop and an
inner loop in conjunction with...
|
by: vince |
last post by:
MSDN help says you can use a UNC path for any methods
that accept a path, and I'm wondering if I can also
substitute an IP address for the UNC....???
Example:
Using System.IO.File.Move()
...
|
by: John G |
last post by:
How can I Programmatically access maximum path, file, and sum of both
lengths? I am using VB.NET 2003.
The PathTooLongException indicates that a path < 248 characters, filename <
260...
|
by: Ollie Riches |
last post by:
I am executing a DTS programmatically from C# using COM interop. Is it
possible to set the 'script file directory' from the C# code?
For anyone else you gets an 'Access Denied Error' when...
|
by: Ffelagund |
last post by:
There are any Path or Directory function to convert an absolute path to
a relative path using a choiced directory as base to calculate the
origin of the relative path?
|
by: Antonio-F100 |
last post by:
Hello,
I need help creating the code for a macro
button on a form that will open a file
directory with windows explorer.
I have about 500 directories with very
long names and only want to...
|
by: gazelle04 |
last post by:
I wanted to create a subfolder in a directory and I used the MkDir statement but it gives me an error like "Path/File access error"
Here are the codes:
MkDir "\\BC123456\Attachments\" &...
|
by: samjnaa |
last post by:
Please check for sanity and approve for posting at python-dev.
Currently file-directory-related functionality in the Python standard
library is scattered among various modules such as shutil, os,...
|
by: vellyna |
last post by:
how to appear path file name?
for example, i have select "books" from list, then i browse the file..
after browse the file, i want to appear the path file name that will save the file in a...
|
by: anupkkumar |
last post by:
Hi All,
Is there any way to copy a file/ directory from one location to the other? The file or the directory name should be given by the user. This is the criteria.
For example:...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |