當前位置: 首頁>>代碼示例>>C#>>正文


C# DirectoryInfo.Exists屬性代碼示例

本文整理匯總了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");
        }
    }
}
開發者ID:.NET開發者,項目名稱:System.IO,代碼行數:37,代碼來源:DirectoryInfo.Exists

示例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();
    }
}
開發者ID:C#程序員,項目名稱:System.IO,代碼行數:31,代碼來源:DirectoryInfo.Exists


注:本文中的System.IO.DirectoryInfo.Exists屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。