本文整理匯總了C#中System.IO.DirectoryInfo.Exists屬性的典型用法代碼示例。如果您正苦於以下問題:C# DirectoryInfo.Exists屬性的具體用法?C# DirectoryInfo.Exists怎麽用?C# DirectoryInfo.Exists使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類System.IO.DirectoryInfo
的用法示例。
在下文中一共展示了DirectoryInfo.Exists屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: CopyDirectory
//引入命名空間
using System;
using System.IO;
namespace DirectoryInfoCS2
{
class Class1
{
// Copy a source directory to a target directory.
static public void CopyDirectory(string SourceDirectory, string TargetDirectory)
{
DirectoryInfo source = new DirectoryInfo(SourceDirectory);
DirectoryInfo target = new DirectoryInfo(TargetDirectory);
//Determine whether the source directory exists.
if(!source.Exists)
return;
if(!target.Exists)
target.Create();
//Copy files.
FileInfo[] sourceFiles = source.GetFiles();
for(int i = 0; i < sourceFiles.Length; ++i)
File.Copy(sourceFiles[i].FullName, target.FullName + "\\" + sourceFiles[i].Name,true);
//Copy directories.
DirectoryInfo[] sourceDirectories = source.GetDirectories();
for(int j = 0; j < sourceDirectories.Length; ++j)
CopyDirectory(sourceDirectories[j].FullName,target.FullName +"\\" + sourceDirectories[j].Name);
}
static void Main(string[] args)
{
CopyDirectory("D:\\Tools","D:\\NewTools");
}
}
}
示例2: Main
//引入命名空間
using System;
using System.IO;
class MainClass {
static void Main(string[] args) {
FileInfo file = new FileInfo("c:\\a.txt");
// Display directory information.
DirectoryInfo dir = file.Directory;
Console.WriteLine("Checking directory: " + dir.Name);
Console.WriteLine("In directory: " + dir.Name);
Console.Write("Directory exists: ");
Console.WriteLine(dir.Exists.ToString());
if (dir.Exists) {
Console.Write("Directory created: ");
Console.WriteLine(dir.CreationTime.ToString());
Console.Write("Directory last updated: ");
Console.WriteLine(dir.LastWriteTime.ToString());
Console.Write("Directory last accessed: ");
Console.WriteLine(dir.LastAccessTime.ToString());
Console.Write("Directory attribute list: ");
Console.WriteLine(dir.Attributes.ToString());
Console.WriteLine("Directory contains: " +
dir.GetFiles().Length.ToString() + " files");
}
Console.WriteLine();
}
}