C# Directory.EnumerateFileSystemEntries的代码示例

通过代码示例来学习C# Directory.EnumerateFileSystemEntries方法

通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。


Directory.EnumerateFileSystemEntries是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的Directory.EnumerateFileSystemEntries() 已经帮大家高亮显示了,大家可以重点学习Directory.EnumerateFileSystemEntries() 方法的写法,从而快速掌握该方法的应用。

Directory.EnumerateFileSystemEntries的代码示例1 - TryCreateEnlistment()

    using System.IO;

        private Result TryCreateEnlistment(
            string fullEnlistmentRootPathParameter,
            string normalizedEnlistementRootPath,
            out GVFSEnlistment enlistment)
        {
            enlistment = null;

            // Check that EnlistmentRootPath is empty before creating a tracer and LogFileEventListener as
            // LogFileEventListener will create a file in EnlistmentRootPath
            if (Directory.Exists(normalizedEnlistementRootPath) && Directory.EnumerateFileSystemEntries(normalizedEnlistementRootPath).Any())
            {
                if (fullEnlistmentRootPathParameter.Equals(normalizedEnlistementRootPath, GVFSPlatform.Instance.Constants.PathComparison))
                {
                    return new Result($"Clone directory '{fullEnlistmentRootPathParameter}' exists and is not empty");
                }

                return new Result($"Clone directory '{fullEnlistmentRootPathParameter}' ['{normalizedEnlistementRootPath}'] exists and is not empty");
            }

            string gitBinPath = GVFSPlatform.Instance.GitInstallation.GetInstalledGitBinPath();
            if (string.IsNullOrWhiteSpace(gitBinPath))
            {
                return new Result(GVFSConstants.GitIsNotInstalledError);
            }

            this.CheckGVFSHooksVersion(tracer: null, hooksVersion: out _);

            try
            {
                enlistment = new GVFSEnlistment(
                    normalizedEnlistementRootPath,
                    this.RepositoryURL,
                    gitBinPath,
                    authentication: null);
            }
            catch (InvalidRepoException e)
            {
                return new Result($"Error when creating a new GVFS enlistment at '{normalizedEnlistementRootPath}'. {e.Message}");
            }

            return new Result(true);
        }
    

开发者ID:microsoft,项目名称:VFSForGit,代码行数:44,代码来源:CloneVerb.cs

在TryCreateEnlistment()方法中,Directory的代码示例类中的EnumerateFileSystemEntries的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

Directory.EnumerateFileSystemEntries的代码示例2 - CanFetchAndCheckoutASingleFolderIntoEmptyGitRepo()

    using System.IO;

        [TestCase]
        public void CanFetchAndCheckoutASingleFolderIntoEmptyGitRepo()
        {
            this.RunFastFetch("--checkout --folders \"/GVFS\" -b " + Settings.Default.Commitish);

            this.CurrentBranchShouldEqual(Settings.Default.Commitish);

            this.fastFetchRepoRoot.ShouldBeADirectory(FileSystemRunner.DefaultRunner);
            List dirs = Directory.EnumerateFileSystemEntries(this.fastFetchRepoRoot).ToList();
            dirs.SequenceEqual(new[]
            {
                Path.Combine(this.fastFetchRepoRoot, ".git"),
                Path.Combine(this.fastFetchRepoRoot, "GVFS"),
                Path.Combine(this.fastFetchRepoRoot, "GVFS.sln")
            });

            Directory.EnumerateFileSystemEntries(Path.Combine(this.fastFetchRepoRoot, "GVFS"), "*", SearchOption.AllDirectories)
                .Count()
                .ShouldEqual(345);

            this.AllFetchedFilePathsShouldPassCheck(path => path.StartsWith("GVFS", FileSystemHelpers.PathComparison));
        }
    

开发者ID:microsoft,项目名称:VFSForGit,代码行数:24,代码来源:FastFetchTests.cs

在CanFetchAndCheckoutASingleFolderIntoEmptyGitRepo()方法中,Directory的代码示例类中的EnumerateFileSystemEntries的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞

Directory.EnumerateFileSystemEntries的代码示例3 - TrySetTimestampsRecursive()

    using System.IO;
        public static void TrySetTimestampsRecursive(string path, DateTime dateTime)
        {
            foreach (string entry in Directory.EnumerateFileSystemEntries(path, "*", SearchOption.AllDirectories))
            {
                if (Directory.Exists(entry))
                {
                    try
                    {
                        Directory.SetCreationTimeUtc(entry, dateTime);
                    }
                    catch { }
                    try
                    {
                        Directory.SetLastAccessTimeUtc(entry, dateTime);
                    }
                    catch { }
                    try
                    {
                        Directory.SetLastWriteTimeUtc(entry, dateTime);
                    }
                    catch { }
                }
                else
                {
                    try
                    {
                        File.SetCreationTimeUtc(entry, dateTime);
                    }
                    catch { }
                    try
                    {
                        File.SetLastAccessTimeUtc(entry, dateTime);
                    }
                    catch { }
                    try
                    {
                        File.SetLastWriteTimeUtc(entry, dateTime);
                    }
                    catch { }
                }
            }
        }
    

开发者ID:gus33000,项目名称:UUPMediaCreator,代码行数:43,代码来源:FolderUtilities.cs

在TrySetTimestampsRecursive()方法中,Directory的代码示例类中的EnumerateFileSystemEntries的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

Directory.EnumerateFileSystemEntries的代码示例4 - Execute()

    using System.IO;

        #endregion

        #region Execute method
        //=====================================================================

        /// 
        /// This is used to execute the task and clean the output folder
        /// 
        /// True on success or false on failure.
        public override bool Execute()
        {
            string projectPath;

            try
            {
                projectPath = Path.GetDirectoryName(Path.GetFullPath(this.ProjectFile));

                // Make sure we start out in the project's output folder
                // in case the output folder is relative to it.
                Directory.SetCurrentDirectory(Path.GetDirectoryName(Path.GetFullPath(projectPath)));

                // Clean the working folder
                if(!String.IsNullOrEmpty(this.WorkingPath))
                {
                    if(!Path.IsPathRooted(this.WorkingPath))
                        this.WorkingPath = Path.GetFullPath(Path.Combine(projectPath, this.WorkingPath));

                    if(Directory.Exists(this.WorkingPath))
                    {
                        BuildProcess.VerifySafePath(nameof(WorkingPath), this.WorkingPath, projectPath);
                        Log.LogMessage(MessageImportance.High, "Removing working folder...");
                        Directory.Delete(this.WorkingPath, true);
                    }
                }

                if(!Path.IsPathRooted(this.OutputPath))
                    this.OutputPath = Path.GetFullPath(Path.Combine(projectPath, this.OutputPath));

                if(Directory.Exists(this.OutputPath))
                {
                    Log.LogMessage(MessageImportance.High, "Removing build files...");
                    BuildProcess.VerifySafePath(nameof(OutputPath), this.OutputPath, projectPath);

                    // Read-only and/or hidden files and folders are ignored as they are assumed to be
                    // under source control.
                    foreach(string file in Directory.EnumerateFiles(this.OutputPath))
                        if((File.GetAttributes(file) & (FileAttributes.ReadOnly | FileAttributes.Hidden)) == 0)
                            File.Delete(file);
                        else
                            Log.LogMessage(MessageImportance.High, "Skipping read-only or hidden file '{0}'", file);

                    Log.LogMessage(MessageImportance.High, "Removing build folders...");

                    foreach(string folder in Directory.EnumerateDirectories(this.OutputPath))
                        try
                        {
                            // Some source control providers have a mix of read-only/hidden files within a folder
                            // that isn't read-only/hidden (i.e. Subversion).  In such cases, leave the folder alone.
                            if(Directory.EnumerateFileSystemEntries(folder, "*", SearchOption.AllDirectories).Any(f =>
                              (File.GetAttributes(f) & (FileAttributes.ReadOnly | FileAttributes.Hidden)) != 0))
                                Log.LogMessage(MessageImportance.High, "Skipping folder '{0}' as it contains read-only or hidden folders/files", folder);
                            else
                                if((File.GetAttributes(folder) & (FileAttributes.ReadOnly | FileAttributes.Hidden)) == 0)
                                    Directory.Delete(folder, true);
                                else
                                    Log.LogMessage(MessageImportance.High, "Skipping folder '{0}' as it is read-only or hidden", folder);
                        }
                        catch(IOException ioEx)
                        {
                            Log.LogMessage(MessageImportance.High, "Did not delete folder '{0}': {1}", folder, ioEx.Message);
                        }
                        catch(UnauthorizedAccessException uaEx)
                        {
                            Log.LogMessage(MessageImportance.High, "Did not delete folder '{0}': {1}", folder, uaEx.Message);
                        }

                    // Delete the log file too if it exists
                    if(!String.IsNullOrEmpty(this.LogFileLocation) && File.Exists(this.LogFileLocation))
                    {
                        Log.LogMessage(MessageImportance.High, "Removing build log...");
                        File.Delete(this.LogFileLocation);
                    }
                }
            }
            catch(Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                Log.LogError(null, "CT0001", "CT0001", "SHFB", 0, 0, 0, 0,
                    "Unable to clean output folder.  Reason: {0}", ex);
                return false;
            }

            return true;
        }
    

开发者ID:EWSoftware,项目名称:SHFB,代码行数:96,代码来源:CleanHelp.cs

在Execute()方法中,Directory的代码示例类中的EnumerateFileSystemEntries的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

Directory.EnumerateFileSystemEntries的代码示例5 - GetItemsAsync()

    using System.IO;

	    /// 
	    public virtual async IAsyncEnumerable GetItemsAsync(StorableKind kind = StorableKind.All, [EnumeratorCancellation] CancellationToken cancellationToken = default)
	    {
		    if (kind == StorableKind.Files)
		    {
			    foreach (var item in Directory.EnumerateFiles(Path))
				    yield return new NativeFile(item);
		    }
		    else if (kind == StorableKind.Folders)
		    {
			    foreach (var item in Directory.EnumerateDirectories(Path))
				    yield return new NativeFolder(item);
		    }
		    else
		    {
			    foreach (var item in Directory.EnumerateFileSystemEntries(Path))
			    {
				    if (File.Exists(item))
					    yield return new NativeFile(item);
				    else
					    yield return new NativeFolder(item);
			    }
		    }

		    await Task.CompletedTask;
	    }
    

开发者ID:files-community,项目名称:Files,代码行数:28,代码来源:NativeFolder.cs

在GetItemsAsync()方法中,Directory的代码示例类中的EnumerateFileSystemEntries的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

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