Home > Net >  Create more child folder
Create more child folder

Time:09-15

How to simplify the code

CodePudding user response:

//refactoring, dry type, you see
Public void CheckFile (string path)
{

Try
{
if(! Directory. The exists (path))
{
Directory. CreateDirectory (path);
}
}
The catch (Exception ex)
{
//loghelper WriteErrlog (ex);
Throw the ex.
}

}

CodePudding user response:

Use directly without judgment, this method itself with judgment, not to build, has not built

CodePudding user response:

Thank you, but I mean, in the same parent folder how to create more child folder; If you create user folder on disk C, then how to this folder to create 10 subfolders (input) don't have to asm

CodePudding user response:

My account Posting is not quite clear, sorry
In the 3 f and then followed by the "in" word
thank you

CodePudding user response:

 DirectoryInfo root=new DirectoryInfo (@ "d:/ABC"); 
if (! Root. The Exists)
Root. The Create ();
New List ()
{
"Ab", "bb"
}. ForEach (p=& gt;
{
Try
{
Root. CreateSubdirectory (p);
}
The catch (Exception e)
{
Console. WriteLine (e);
Throw;
}

});
  •  Tags:  
  • C#
  • Related