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