none
Directory.CreateDirectory doesn't work. RRS feed

  • Question

  • Hello. It doesn't work if there is a file with the same name. It looks like a bug.

    And i'm stuck now because i need a file with the same name.

    • Edited by Booster1 Monday, June 10, 2013 2:38 PM
    Monday, June 10, 2013 2:33 PM

Answers

  • You want C:\foo to refer to both a file and a folder?  Impossible.

    You can't have a file and a folder of the same name (if they have the same parent folder).

    Why do you feel like you need a file that has the same name as the folder?  Or a folder that has the same name as some other file?

    Is it not sufficient to give your file an extension and your folder no extension?  something like:

    A folder:
    C:\foo

    and a file:
    C:\foo.txt

    In the most extreme case,  you can integrate into the shell something like what .zip files do, but it's a little heavy handed.  Right now it sounds like you can easily work around your problem by giving the folder and file subtly different names.



    And no, it's not a bug.

    From the documentation for Directory.CreateDirectory:

    Exception Condition
    IOException

    The directory specified by path is a file.

    • Edited by Wyck Monday, June 10, 2013 3:49 PM more info about the supposed "bug"
    • Proposed as answer by Reed Copsey, JrMVP, Moderator Monday, June 10, 2013 4:53 PM
    • Marked as answer by Booster1 Monday, June 10, 2013 5:00 PM
    Monday, June 10, 2013 3:46 PM

All replies

  • Something has to give.  You can't do this in Explorer.  That prevents you from doing it in your code.
    Monday, June 10, 2013 2:51 PM
  • Ok. Isn't it strange?
    Monday, June 10, 2013 3:02 PM
  • You want C:\foo to refer to both a file and a folder?  Impossible.

    You can't have a file and a folder of the same name (if they have the same parent folder).

    Why do you feel like you need a file that has the same name as the folder?  Or a folder that has the same name as some other file?

    Is it not sufficient to give your file an extension and your folder no extension?  something like:

    A folder:
    C:\foo

    and a file:
    C:\foo.txt

    In the most extreme case,  you can integrate into the shell something like what .zip files do, but it's a little heavy handed.  Right now it sounds like you can easily work around your problem by giving the folder and file subtly different names.



    And no, it's not a bug.

    From the documentation for Directory.CreateDirectory:

    Exception Condition
    IOException

    The directory specified by path is a file.

    • Edited by Wyck Monday, June 10, 2013 3:49 PM more info about the supposed "bug"
    • Proposed as answer by Reed Copsey, JrMVP, Moderator Monday, June 10, 2013 4:53 PM
    • Marked as answer by Booster1 Monday, June 10, 2013 5:00 PM
    Monday, June 10, 2013 3:46 PM
  • I agree now folder is a file but has different attributes. Thank you for help.
    Monday, June 10, 2013 5:00 PM