本文整理汇总了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())
{
}
}
}
}