Created
January 17, 2018 05:17
-
-
Save imAliAsad/67681da7a82687259f23c1541059611b to your computer and use it in GitHub Desktop.
Create a file or folder if it doesn't exist in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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