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 55264
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: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |