How to determine if a remote path was a file or directory using C # .Net?
thanks
Assuming the file / directory really exists, you can use two static methods:
Both take one string argument and return a boolean if the file / directory exists.
- , / - , - " /" /, , () . ", " ", " . :
:
c:\windows\
c:\windows
c:\windows\notepad.exe
c:\windows\system32\drivers\etc\hosts
, , , .
Directory.Exists(...) , false. , File.Exists(...) , false
: path.GetFileName
, Empty, , , .
, , , , "myfile.txt". , , , .
File.Exists Directory.Exists GetFileAttributesEx, , , . , - .
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetError = true)] static extern int GetFileAttributes(string lpFileName); bool IsDirectory(string path) { return GetFileAttributes(path) & 16 == 16; }
Directory.Exists File.Exists, , .
Directory.Exists
File.Exists
. .
if (Path.HasExtension(fileFolderPath) && !string.IsNullOrEmpty(Path.GetFileName(fileFolderPath))) { //path is for file }
Directory.Exists File.Exists , .
Source: https://habr.com/ru/post/1716965/More articles:What are the basic knowledge requirements for a Perl developer? - perlDisplay XML file with XSL on an existing web page - htmlDisplaying database query data in the form of a table - c #Setting the Dump class - objective-cGetting an array of strings from an array of objects - arraysConvert NSString with a number to the appropriate localization format for a phone number - objective-cWhy is my regex matching version number not working? - regexA standalone GTK application when there is no X window environment - linuxHow to create a url to open a page using the jQuery lightbox plugin color window? - jqueryJava, Java VM, Java Platform, - javaAll Articles