If you have a full path like: "C:\dir0\dir1\dir2\dir3\dir4\" how would you best implement it so that all directories are present?
Is there a method for this in the BCL? If not, what’s the most elegant way to do this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I would call
Directory.CreateDirectory(@"C:\dir0\dir1\dir2\dir3\dir4\").Contrary to popular belief,
Directory.CreateDirectorywill automatically create whichever parent directories do not exist.In MSDN’s words,
Creates all directories and subdirectories as specified by path.If the entire path already exists, it will do nothing. (It won’t throw an exception)