本文整理匯總了C#中System.IO.DirectoryInfo.Create_If_NotExists方法的典型用法代碼示例。如果您正苦於以下問題:C# DirectoryInfo.Create_If_NotExists方法的具體用法?C# DirectoryInfo.Create_If_NotExists怎麽用?C# DirectoryInfo.Create_If_NotExists使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.IO.DirectoryInfo
的用法示例。
在下文中一共展示了DirectoryInfo.Create_If_NotExists方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: CopyAllFilesInDirectoryToDirectory
private int CopyAllFilesInDirectoryToDirectory(String sourceDirectory, String targetDirectory)
{
try
{
DirectoryInfo targetDirectoryInfo = new DirectoryInfo(targetDirectory);
targetDirectoryInfo.Create_If_NotExists();
}
catch (Exception Excp)
{
return -1;
}
DirectoryInfo sourceDirectoryInfo = new DirectoryInfo(sourceDirectory);
int numberOfProcessedFiles = 0;
foreach (FileInfo enumerateFile in sourceDirectoryInfo.EnumerateFiles())
{
try
{
String targetFile = Path.Combine(targetDirectory, Path.GetFileName(enumerateFile.FullName));
if (File.Exists(targetFile))
File.Delete(targetFile);
enumerateFile.CopyTo(targetFile);
numberOfProcessedFiles++;
}
catch (Exception Excp)
{
ProtokollList.Add($"{Excp}");
return -1;
}
}
return numberOfProcessedFiles;
}
示例2: CreatePPTPictureWorkingDirectories
public void CreatePPTPictureWorkingDirectories()
{
DirectoryInfo pptDir = new DirectoryInfo(RootDirectoryForPPTWorkingPictures);
pptDir.Create_If_NotExists();
foreach (Projekt projekt in Data.DbServer3.WordUp.Projekte.Find_PhasenCorrectProjekte("Planungen")
.OrderBy(ord => ord.NumericProjektId))
{
DirectoryInfo pptSubDir = new DirectoryInfo(Path.Combine(pptDir.FullName, projekt.SubDirectoryForPPTWorkingPictures));
pptSubDir.Create_If_NotExists();
}
}
示例3: ImportPicturesFromPPTWorkingDirectories
public void ImportPicturesFromPPTWorkingDirectories()
{
DirectoryInfo pptDir = new DirectoryInfo(RootDirectoryForPPTWorkingPictures);
pptDir.Create_If_NotExists();
String projektNumberPrefix = $"{Data.DbServer3.WordUp.ActuallWordUpYear.Substring(0, 2)}0";
/*
* if (targetProjekt != WordUpProjekteModellInstance.SelectedProjekt)
return;
if (!ConnectedMaterialHandlerModell.IsValidPictureDropSource(e))
return;
ConnectedMaterialHandlerModell MaterialHandlerModell = new ConnectedMaterialHandlerModell();
MaterialHandlerModell.ProjekteModellInstance = WordUpProjekteModellInstance;
//MaterialHandlerModell.WordUpOrteHandlerModelInstance = WordUpOrteHandlerModelInstance;
MaterialJPGForeignKeyConnectorenTyp TargetForeignTyp = Data.DbServer3.Blob.MaterialJPGForeignKeyConnectorenTypen
.Find_MaterialJPGTypViaName((String)source.Tag);
String[] FilesToImport = ConnectedMaterialHandlerModell.GetPictureFileDropSource(e);
MaterialJPGTyp TargetMaterialTyp = Data.DbServer3.Blob.MaterialJPGTypen.Find(MaterialienTypen.OrtsBild);
if (MaterialHandlerModell.ImportData(FilesToImport, targetProjekt.Ort, TargetMaterialTyp,
FilesToImport.Length > 1, targetProjekt.Id, TargetForeignTyp) == null)
{
MessageBox.Show("Es trat ein Fehler auf");
return;
}
* */
foreach (DirectoryInfo ortsTeilDirectory in pptDir.EnumerateDirectories())
{
foreach (DirectoryInfo subDirectory in ortsTeilDirectory.EnumerateDirectories())
{
String numericProjektId = projektNumberPrefix + subDirectory.Name.Substring(0, 3);
Projekt projekt = Data.DbServer3.WordUp.Projekte.GetProjektViaNumericProjektID(numericProjektId);
if (projekt == null)
throw new Exception($"Kein Projekt für Id {numericProjektId}");
foreach (FileInfo pictureFile in subDirectory.EnumerateFiles())
{
}
}
}
}