当前位置: 首页>>代码示例>>C#>>正文


C# DirectoryInfo.GetDirectories方法代码示例

本文整理汇总了C#中DirectoryInfo.GetDirectories方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryInfo.GetDirectories方法的具体用法?C# DirectoryInfo.GetDirectories怎么用?C# DirectoryInfo.GetDirectories使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DirectoryInfo的用法示例。


在下文中一共展示了DirectoryInfo.GetDirectories方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DirectoryCopy

	private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs)
	{
		DirectoryInfo dir = new DirectoryInfo(sourceDirName);
		DirectoryInfo[] dirs = dir.GetDirectories();

		if (!dir.Exists)
		{
			throw new DirectoryNotFoundException(
				"Source directory does not exist or could not be found: "
				+ sourceDirName);
		}

		if (!Directory.Exists(destDirName))
		{
			Directory.CreateDirectory(destDirName);
		}

		FileInfo[] files = dir.GetFiles();
		foreach (FileInfo file in files)
		{
			string temppath = Path.Combine(destDirName, file.Name);
			file.CopyTo(temppath, true);
		}

		if (copySubDirs)
		{
			foreach (DirectoryInfo subdir in dirs)
			{
				string temppath = Path.Combine(destDirName, subdir.Name);
				DirectoryCopy(subdir.FullName, temppath, copySubDirs);
			}
		}
	}
开发者ID:Charkova,项目名称:MetaEden.a14,代码行数:33,代码来源:CoherentPostProcessor.cs

示例2: CopyAll

    /// <summary>
    /// Recursive Copy Directory Method
    /// </summary>
    private static void CopyAll(DirectoryInfo source, DirectoryInfo target)
    {
        // Check if the source directory exists, if not, don't do any work.
        if (!Directory.Exists(source.FullName))
        {
            return;
        }

        // Check if the target directory exists, if not, create it.
        if (!Directory.Exists(target.FullName))
        {
            Directory.CreateDirectory(target.FullName);
        }

        // Copy each file into it’s new directory.
        foreach (var fileInfo in source.GetFiles())
        {
            fileInfo.CopyTo (Path.Combine (target.ToString (), fileInfo.Name), true);
        }

        // Copy each subdirectory using recursion.
        foreach (var subDirInfo in source.GetDirectories())
        {
            DirectoryInfo nextTargetSubDir = target.CreateSubdirectory(subDirInfo.Name);
            CopyAll(subDirInfo, nextTargetSubDir);
        }
    }
开发者ID:Fertogo,项目名称:Rox-Star,代码行数:30,代码来源:KinectCopyPluginDataHelper.cs

示例3: DeleteIfExists

 public static string DeleteIfExists(DirectoryInfo root, string sub)
 {
     if (root.GetDirectories().Any(x => x.Name.Equals(sub, System.StringComparison.OrdinalIgnoreCase))) {
             root.GetDirectories(sub).First().Delete();
             return "Deleted " + sub;
         }
         return " -- " + sub + " directory not present";
 }
开发者ID:cbrooker,项目名称:grumbler,代码行数:8,代码来源:GitRunner.cs

示例4: AssetsConvertLineEndings

 /// <summary>
 /// Recursively convert all source files and subfolders
 /// </summary>
 /// <param name="directory"></param>
 public static void AssetsConvertLineEndings(DirectoryInfo directory)
 {
     if (null == directory)
     {
         return;
     }
     // get all source files
     foreach (string extension in EXTENSION_SOURCE)
     {
         foreach (FileInfo file in directory.GetFiles(extension))
         {
             ConvertAsset(file);
         }
     }
     // scan subfolders
     foreach (DirectoryInfo subDir in directory.GetDirectories())
     {
         if (null == subDir)
         {
             continue;
         }
         if (subDir.Name.ToUpper().Equals(".SVN"))
         {
             continue;
         }
         //Debug.Log(string.Format("Directory: {0}", subDir));
         AssetsConvertLineEndings(subDir);
     }
 }
开发者ID:robinpan,项目名称:bear_minimum,代码行数:33,代码来源:MenuAssetsConvertToDosLineEndings.cs

示例5: LoadFolders

    public void LoadFolders()
    {
        if (Directory.Exists(this.RealImagePath)) {
            DirectoryInfo _currentFolder = new DirectoryInfo(this.current_path.Value);
            DirectoryInfo[] _subs = _currentFolder.GetDirectories();

            this.FolderList.DataSource = _subs;
            this.FolderList.DataBind();
            //get files in patterns
            string[] pattern = { "*.jpg", "*.jpeg", "*.gif" ,"*.png","*.bmp"};
            List<FileInfo> _imagesFound = new List<FileInfo>();
            foreach (string filter in pattern) {
                _imagesFound.AddRange(_currentFolder.GetFiles(filter));
            }
            this.FileList.DataSource = _imagesFound;
            this.FileList.DataBind();

            //Response.Write(_currentFolder.FullName);
            //Response.Write(Server.MapPath(this._rootPath));

            if (!_currentFolder.FullName.Equals( Server.MapPath(this._rootPath),StringComparison.InvariantCulture))
            {
                DirectoryInfo _parent = _currentFolder.Parent;

                this.go_up_btn.CommandArgument = _parent.FullName + "\\";
                this.go_up_btn.Visible = true;

            }
            else
            {
                this.go_up_btn.Visible = false;
            }
            this.current_folder_name_lbl.Text = this.current_path.Value;
        }
    }
开发者ID:abdul-baten,项目名称:hbcms,代码行数:35,代码来源:FilesAndForlders.aspx.cs

示例6: Main

	static void Main ()
	{
		DirectoryInfo di;
		DirectoryInfo [] dirs;
		FileInfo [] files;

		string basedir = AppDomain.CurrentDomain.BaseDirectory;

		di = new DirectoryInfo (basedir);
		dirs = di.GetDirectories ();
		files = di.GetFiles ();

		Assert.AreEqual (3, dirs.Length, "#A1");
		Assert.AreEqual (".svn", dirs [0].Name, "#A2");
		Assert.AreEqual ("dirB", dirs [1].Name, "#A3");
		Assert.AreEqual ("test", dirs [2].Name, "#A4");

		Assert.AreEqual (4, files.Length, "#B1");
		Assert.AreEqual ("default.build", files [0].Name, "#B2");
		Assert.AreEqual ("fileB.txt", files [1].Name, "#B3");
		Assert.AreEqual ("test.cs", files [2].Name, "#B4");
		Assert.AreEqual ("test.exe", files [3].Name, "#B5");

		di = new DirectoryInfo (Path.Combine (basedir, "dirB"));
		dirs = di.GetDirectories ();
		files = di.GetFiles ();

		Assert.AreEqual (0, dirs.Length, "#C1");

		Assert.AreEqual (1, files.Length, "#D1");
		Assert.AreEqual ("fileA.tmp", files [0].Name, "#D2");
	}
开发者ID:mono,项目名称:gert,代码行数:32,代码来源:test.cs

示例7: GetAssets

 public static void GetAssets(string extension, Dictionary<string, string> files, DirectoryInfo directory)
 {
     if (null == directory)
     {
         return;
     }
     foreach (FileInfo file in directory.GetFiles(extension))
     {
         if (string.IsNullOrEmpty(file.FullName) ||
             files.ContainsKey(file.FullName.ToLower()))
         {
             continue;
         }
         files.Add(file.FullName.ToLower(), file.FullName);
     }
     foreach (DirectoryInfo subDir in directory.GetDirectories())
     {
         if (null == subDir)
         {
             continue;
         }
         if (subDir.Name.ToUpper().Equals(".SVN"))
         {
             continue;
         }
         //Debug.Log(string.Format("Directory: {0}", subDir));
         GetAssets(extension, files, subDir);
     }
 }
开发者ID:thoniorf,项目名称:ouya-sdk-examples,代码行数:29,代码来源:OuyaMenuAdmin.cs

示例8: destroyOldExcel

 /// <summary>
 /// Destory Old Excel
 /// </summary>
 private void destroyOldExcel()
 {
     try
     {
         string path = Server.MapPath("~") + @"ExcelReport\";
         string folderName = DateTime.Now.ToString("yyyyMMdd");
         DirectoryInfo root = new DirectoryInfo(path);
         DirectoryInfo[] nodes = root.GetDirectories();
         FileInfo[] files = null;
         for (int i = 0; i < nodes.Length; i++)
         {
             if (!string.Equals(nodes[i].Name, folderName))
             {
                 files = nodes[i].GetFiles();
                 for (int j = 0; j < files.Length; j++)
                 {
                     if (files[j].Attributes.ToString().IndexOf("ReadOnly") != -1)
                     {
                         files[j].Attributes = FileAttributes.Normal;
                     }
                     files[j].Delete();
                 }
                 nodes[i].Delete();
             }
         }
     }
     catch { }
 }
开发者ID:gracianani,项目名称:SINO_CRM,代码行数:31,代码来源:SiemensCRMEnter.aspx.cs

示例9: GetDirectoriesSizes

    private static long GetDirectoriesSizes(Dictionary<string, long> directoriesSizes, DirectoryInfo currentFolder)
    {
        long filesSum = currentFolder.GetFiles().Select(f => f.Length).Sum();
        directoriesSizes[currentFolder.Name] = filesSum;
        if (currentFolder.GetDirectories().Length == 0)
        {
            return directoriesSizes[currentFolder.Name];
        }

        foreach (var directory in currentFolder.GetDirectories())
        {
            directoriesSizes[currentFolder.Name] += GetDirectoriesSizes(directoriesSizes, directory);
        }

        return directoriesSizes[currentFolder.Name];
    }
开发者ID:vangelov-i,项目名称:Fundamentals,代码行数:16,代码来源:TraverseAndSaveWithTree.cs

示例10: CopyAll

    /// <summary>
    /// Verzeichnis rekursiv kopieren. Vorhandene Dateien werden überschreiben
    /// </summary>
    /// <param name="source">QuellVERZEICHNIS</param>
    /// <param name="target">ZielVERZEICHNIS</param>
    /// <param name="dirCount">für jedes erzeugte Verzeichnis +=1</param>
    /// <param name="fileCount">für jede erzeugte Datei +=1</param>
    public static void CopyAll(
		DirectoryInfo source,
		DirectoryInfo target,
		ref int dirCount,
		ref int fileCount)
    {
        // Check if the target directory exists, if not, create it.
        if (!Directory.Exists(target.FullName))
        {
            dirCount++;
            Directory.CreateDirectory(target.FullName);
            Logger.Log("Verzeichnis erstellt: " + target.FullName);
        }

        // Copy each file into it’s new directory.
        foreach (FileInfo fi in source.GetFiles())
        {
            fileCount++;
            fi.CopyTo(Path.Combine(target.ToString(), fi.Name), true);
            Logger.Log("Datei kopiert: " + fi.FullName);
        }

        // Copy each subdirectory using recursion.
        foreach (DirectoryInfo diSrcSubDir in source.GetDirectories())
        {
            dirCount++;
            DirectoryInfo diNext = target.CreateSubdirectory(diSrcSubDir.Name);
            CopyAll(diSrcSubDir, diNext, ref dirCount, ref fileCount);
        }
    }
开发者ID:Jonas90,项目名称:iss,代码行数:37,代码来源:FileHelper.cs

示例11: FindAllFiles

    private static void FindAllFiles(DirectoryInfo directory)
    {
        try
        {
            var childDirectories = directory.GetDirectories();
            foreach (var dir in childDirectories)
            {
                FindAllFiles(dir);
            }
        }
        catch (UnauthorizedAccessException uae)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(uae.Message);
            Console.ForegroundColor = ConsoleColor.Gray;
        }

        var filesInDirectory = directory.GetFiles();
        foreach (var file in filesInDirectory)
        {
            if (file.Extension == extension)
            {
                Console.WriteLine(file.DirectoryName);
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine(file.Name);
                Console.ForegroundColor = ConsoleColor.Gray;
            }
        }
    }
开发者ID:bahtev,项目名称:TelerikAcademy,代码行数:29,代码来源:TraverseCWindowsDirectory.cs

示例12: TreverseDirectories

    private static void TreverseDirectories(XmlTextWriter writer, DirectoryInfo dir)
    {
        var folders = dir.GetDirectories();
        var files = dir.GetFiles();
        writer.WriteStartElement("folder");
        writer.WriteElementString("name", dir.Name);

        try
        {
            if (files.Count() > 0)
            {
                writer.WriteStartElement("files");
                foreach (var file in files)
                {
                    writer.WriteElementString("name", file.Name);
                }

                writer.WriteEndElement();
            }

            foreach (var child in folders)
            {
                TreverseDirectories(writer, child);
            }

            writer.WriteEndElement();
        }
        catch (Exception)
        {
            Console.WriteLine("Access denied! ");
        }
    }
开发者ID:aleks-todorov,项目名称:HomeWorks,代码行数:32,代码来源:TraversingDirectory.cs

示例13: AddNodeAndDescendents

    protected TreeNode AddNodeAndDescendents(DirectoryInfo folder, TreeNode parentNode)
    {
        // displaying the folder's name and storing the full path to the folder as the value
        string virtualFolderPath;
        if (parentNode == null)
        {
            virtualFolderPath = VirtualSiteRoot;
        }
        else
        {
            virtualFolderPath = parentNode.Value + folder.Name + "/";
        }

        TreeNode node = new TreeNode(folder.Name, virtualFolderPath);
        node.Selected = (folder.Name == selectedFolderName);

        // Recurse through this folder's subfolders
        DirectoryInfo[] subFolders = folder.GetDirectories();
        foreach (DirectoryInfo subFolder in subFolders)
        {
            if (subFolder.Name != "App_Data")
            {
                TreeNode child = AddNodeAndDescendents(subFolder, node);
                node.ChildNodes.Add(child);
            }
        }
        // Return the new TreeNode
        return node;
    }
开发者ID:camiloamora,项目名称:AppAjc,代码行数:29,代码来源:access-rules.ascx.cs

示例14: ShowDirectory

    public int ShowDirectory(DirectoryInfo curDir, int inLevel, ArrayList dirs)
    {
        int i;
        string indent = "";

        try
        {
            for (i = 0; i < visits; i++)
            {
                indent += TAB;
            }

            dirs.Add(indent + curDir.Name);
            visits++;

            foreach (DirectoryInfo subDir in curDir.GetDirectories())
            {
                dirCounter++;
                ShowDirectory(subDir, visits, dirs);
                //FileInfo[] files = subdir.GetFiles();
            }
            visits--;
            if (indent.Length > 0)
                indent.Substring(0, indent.Length - TAB.Length);
        }
        catch (Exception ex)
        {
            return -1;
        }
        return dirCounter;
    }
开发者ID:Greg-Personal,项目名称:Personal,代码行数:31,代码来源:clsDirectory.cs

示例15: IsGitRepo

 public static bool IsGitRepo(string dirPath)
 {
     if (!Directory.Exists(dirPath))
             return false;
         var dir = new DirectoryInfo(dirPath);
         return dir.GetDirectories().Any(x => x.Name == ".git");
 }
开发者ID:cbrooker,项目名称:grumbler,代码行数:7,代码来源:GitRunner.cs


注:本文中的DirectoryInfo.GetDirectories方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。