Guest User

Untitled

a guest
Jul 16th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. if (sourcePath.Contains(".")) // then treat this path as a file
  2.  
  3. if (File.Exists(sourcePath))
  4. {
  5. // then treat this path as a file
  6. }
  7.  
  8. if(File.Exists(path))
  9. {
  10. // This path is a file
  11. ProcessFile(path);
  12. }
  13. else if(Directory.Exists(path))
  14. {
  15. // This path is a directory
  16. ProcessDirectory(path);
  17. }
  18. else
  19. {
  20. Console.WriteLine("{0} is not a valid file or directory.", path);
  21. }
  22.  
  23. public bool IsFolder(string path)
  24. {
  25. return ((File.GetAttributes(path) & FileAttributes.Directory) == FileAttributes.Directory);
  26. }
  27.  
  28. Public Function IsFolder(path As String) As Boolean
  29. Return ((File.GetAttributes(path) And FileAttributes.Directory) = FileAttributes.Directory)
  30. End Function
  31.  
  32. Try
  33. Dim isExistingFolder As Boolean = IsFolder(path)
  34. Dim isExistingFile = Not isExistingFolder
  35. Catch fnfEx As FileNotFoundException
  36. '.....
  37. End Try
  38.  
  39. var isDirectory = (File.GetAttributes(path) & FileAttributes.Directory) == FileAttributes.Directory;
  40.  
  41. public bool IsFolder(string path)
  42. {
  43. return ((File.GetAttributes(path) & FileAttributes.Directory) == FileAttributes.Directory);
  44. }
  45.  
  46. // Define a test path
  47. string filePath = @"C:Test Folder";
  48.  
  49. if (IsFolder(filePath)){
  50. MessageBox.Show("The given path is a folder.");
  51. }
  52. else {
  53. MessageBox.Show("The given path is a file.");
  54. }
Add Comment
Please, Sign In to add comment