none
Check if path is file or a directory RRS feed

  • Question

  • hello,

    i get a path as a parameter in a method. this path contains a path to a new directory or to a new file that i have to create / copy to a specific directory.

    when i got a path to a file i have to use the method File.Copy(pathTocheck, x)

    if i got a path which is a directory i have to use Directory.Create(adjustedpath)

    but i dont know how to check if the path is a file or a path to a directory.

    i tried the method GetFileName to validate if the path contains a file. but the method returns always a string. so i cant use this function to check if the path is a string or a file.

    with which function i can check if the path is a directory or a file?

    greetings
    http://get.lima-city.de
    Thursday, December 24, 2009 8:45 PM

Answers

All replies

  • Use System.IO.File.Exists method. if return false then is a directory else is a file.
    You can also use System.IO.Directory.Exists method.
    With best regards, Yasser Zamani
    Thursday, December 24, 2009 8:57 PM
  • hello,

    im using a third party assembly which implements all classes and funktion from System.IO. The third party assembly supports long paths. i need this support.
    the problem is that the function of the third party returns a false value.
    the function from the third party File.Exits(path) returns always true. so i cant check if the path is a file or a directory.


    is there a windows api function that i can validate this issue?

    greetings
    http://get.lima-city.de
    Thursday, December 24, 2009 9:05 PM
  • Ask support for your 3rd party library to fix their implementation of the API.
    From Windows API you could use FindFirstFile - it returns FILE_ATTRIBUTE_DIRECTORY set or cleared. (BTW: This is not the right forum to ask Windows API questions)

    -Karel
    • Marked as answer by martin.doku Saturday, December 26, 2009 12:36 PM
    Friday, December 25, 2009 11:23 PM
    Moderator