locked
Need help with System.IO.Directory.CreateDirectory RRS feed

  • Question

  • User1077245351 posted

    I have a question:

    The code below is used to create a folder called "TestSubFolder" in the specified path.  If the "TestFolder doesn't exist, which of the following will occur?

    System.IO.Directory.CreativeDirectory(@"C:\TestFolder\TestSubFolder");

    Responses:

    1. Only the test SubFolder will be created
    2. An exception will be thrown due to an invalid path
    3. An exception will be thrown stating that the folder couldn't be created

    I choose number 2, is that correct?

    You help is appreciated.  Thanks.

    Wednesday, March 6, 2019 1:37 AM

Answers

  • User-1174608757 posted

    Hi slb2012,

    The code you provide is 

    System.IO.Directory.CreativeDirectory(@"C:\TestFolder\TestSubFolder");

    I think you want to say is 

    System.IO.Directory.CreateDirectory(@"C:\TestFolder\TestSubFolder");

    I have tried on my side , if TestFolder doesn't exists , program will automatically create it in C disk then program will create a TestSubFolder in it .There is no exception.

    Best Regards

    Wei Zhang

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 6, 2019 5:49 AM

All replies

  • User475983607 posted

    I have a question:

    The code below is used to create a folder called "TestSubFolder" in the specified path.  If the "TestFolder doesn't exist, which of the following will occur?

    System.IO.Directory.CreativeDirectory(@"C:\TestFolder\TestSubFolder");

    Responses:

    1. Only the test SubFolder will be created
    2. An exception will be thrown due to an invalid path
    3. An exception will be thrown stating that the folder couldn't be created

    I choose number 2, is that correct?

    You help is appreciated.  Thanks.

    None of the above.  The code does not compile "CreativeDirectory()" is not a valid method of Directory object.

    Wednesday, March 6, 2019 1:47 AM
  • User1077245351 posted

    Really?! I was doing some test for C# 5.0 by selecting answer 2 it gave me an error!!! and you said the code doesn't compile because is not a valid method of <g class="gr_ gr_205 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar only-ins doubleReplace replaceWithoutSep" id="205" data-gr-id="205">Directory</g> object.

    I feel like I am a little stuck here thinking which response I will select?

    Wednesday, March 6, 2019 1:54 AM
  • User-1174608757 posted

    Hi slb2012,

    The code you provide is 

    System.IO.Directory.CreativeDirectory(@"C:\TestFolder\TestSubFolder");

    I think you want to say is 

    System.IO.Directory.CreateDirectory(@"C:\TestFolder\TestSubFolder");

    I have tried on my side , if TestFolder doesn't exists , program will automatically create it in C disk then program will create a TestSubFolder in it .There is no exception.

    Best Regards

    Wei Zhang

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 6, 2019 5:49 AM
  • User1077245351 posted

    Thanks for your response.  I made a little mistake in the word: instead of CreativeDirectory should be CreateDirectory.  I am surprised that I wrote CreativeDirectory.  But thanks anyway for your help. I really appreciated it.  I know the right answer is the number one:  Only the TestSubFolder will be created with no error exception.  Thanks again.

    Wednesday, March 6, 2019 8:01 AM
  • User475983607 posted

    Thanks for your response.  I made a little mistake in the word: instead of CreativeDirectory should be CreateDirectory.  I am surprised that I wrote CreativeDirectory.  But thanks anyway for your help. I really appreciated it.  I know the right answer is the number one:  Only the TestSubFolder will be created with no error exception.  Thanks again.

    The devil is in the details.  

    Keep in mind it is very difficult to infer intent on the forum when the code has syntax errors.  In these cases we have to guess what you are trying to do.  I thought this was a trick question.

    Wednesday, March 6, 2019 12:42 PM
  • User303363814 posted

    Why ask a forum?  Run the code and see what happens.  Guaranteed to be the 100% correct answer.

    Seriously, you learn to program by writing, running and debugging programs.  Doing tests won't make you a programmer.

    Wednesday, March 6, 2019 9:12 PM