Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (sourcePath.Contains(".")) // then treat this path as a file
- if (File.Exists(sourcePath))
- {
- // then treat this path as a file
- }
- if(File.Exists(path))
- {
- // This path is a file
- ProcessFile(path);
- }
- else if(Directory.Exists(path))
- {
- // This path is a directory
- ProcessDirectory(path);
- }
- else
- {
- Console.WriteLine("{0} is not a valid file or directory.", path);
- }
- public bool IsFolder(string path)
- {
- return ((File.GetAttributes(path) & FileAttributes.Directory) == FileAttributes.Directory);
- }
- Public Function IsFolder(path As String) As Boolean
- Return ((File.GetAttributes(path) And FileAttributes.Directory) = FileAttributes.Directory)
- End Function
- Try
- Dim isExistingFolder As Boolean = IsFolder(path)
- Dim isExistingFile = Not isExistingFolder
- Catch fnfEx As FileNotFoundException
- '.....
- End Try
- var isDirectory = (File.GetAttributes(path) & FileAttributes.Directory) == FileAttributes.Directory;
- public bool IsFolder(string path)
- {
- return ((File.GetAttributes(path) & FileAttributes.Directory) == FileAttributes.Directory);
- }
- // Define a test path
- string filePath = @"C:Test Folder";
- if (IsFolder(filePath)){
- MessageBox.Show("The given path is a folder.");
- }
- else {
- MessageBox.Show("The given path is a file.");
- }
Add Comment
Please, Sign In to add comment