Skip to content

Instantly share code, notes, and snippets.

@imAliAsad
Created January 17, 2018 05:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imAliAsad/67681da7a82687259f23c1541059611b to your computer and use it in GitHub Desktop.
Save imAliAsad/67681da7a82687259f23c1541059611b to your computer and use it in GitHub Desktop.
Create a file or folder if it doesn't exist in C#
string path = @"E:\FamilyBrowser\";
string FullPath = @"E:\FamilyBrowser\Architecture\Annotation\Cable Tray\Fittings\Channel Horizontal Bend.rfa";
// Extract file path info
var newpath = FullPath.Replace(path, "");
newpath = newpath.Replace(".rfa", "");
newpath = path + @"IMG\" + newpath;
// Store File Path Info
var fileinfo = new System.IO.FileInfo(newpath + ".png");
if (!fileinfo.Exists)
{
//Create directory if it doesn't exist
System.IO.Directory.CreateDirectory(fileinfo.Directory.FullName);
//Then create the file here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment