Advertisement
benshepherd

(C#) Create folders if not exist

Sep 21st, 2012
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.66 KB | None | 0 0
  1.         private void createDirs(string str)
  2.         {
  3.             string[] dirs = str.Split('\\');
  4.             string new_str = String.Empty;
  5.  
  6.             foreach (string dir in dirs)
  7.             {
  8.                 new_str += dir + "\\";
  9.                 if (Directory.Exists(new_str) == false)
  10.                 {
  11.                     try
  12.                     {
  13.                         Directory.CreateDirectory(new_str);
  14.                     }
  15.                     catch (Exception ex)
  16.                     {
  17.                         MessageBox.Show(ex.ToString(), "Error creating directories");
  18.                     }
  19.                 }
  20.             }
  21.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement