C# DirectoryInfo.Equals的代码示例

通过代码示例来学习C# DirectoryInfo.Equals方法

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


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

DirectoryInfo.Equals的代码示例1 - Install()

    using System.IO;
        static void Install()
        {
            Console.WriteLine("Installing...");
            foreach (string dir in Directory.GetDirectories("master/"))
            {
                SetAccessRule(folderDir);
                SetAccessRule(dir);

                string dirName = new DirectoryInfo(dir).Name;
                string destDir = Path.Combine(folderDir, dirName + @"\");

                //Skip hash directory
                if (dirName.Equals("Hashes", StringComparison.CurrentCultureIgnoreCase))
                    continue;

                if (Directory.Exists(destDir))
                {
                    Directory.Delete(destDir, true);
                }

                if (Directory.Exists(destDir))
                    Directory.Delete(destDir, true);

                Directory.Move(dir, destDir);
            }
            foreach (string file in Directory.GetFiles("master/"))
            {
                if (file.Contains("Updater.exe") || file.Contains("Updater.exe.config")
                    || file.Contains("Updater.pdb") || file.Contains("Octokit.dll"))
                    continue;

                SetAccessRule(file);
                SetAccessRule(folderDir);

                string destFile = Path.Combine(folderDir, Path.GetFileName(file));
                if (File.Exists(destFile))
                    File.Delete(destFile);

                File.Move(file, destFile);
            }
        }
    

开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:42,代码来源:Program.cs

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

DirectoryInfo.Equals的代码示例2 - MatchIncludeInParentPath()

    using System.IO;

        private string MatchIncludeInParentPath(string filePath, string initialDirectory, IncludeType includeMatchType)
        {
            string matchPath = Path.Combine(initialDirectory, filePath);
            bool matchPathExists = Util.FileExists(matchPath);

            if (matchPathExists && includeMatchType == IncludeType.NearestMatchInParentPath)
            {
                return matchPath;
            }

            // backtrace one level in the path
            string matchResult = null;
            DirectoryInfo info = Directory.GetParent(initialDirectory);
            if (info != null)
            {
                string parentPath = info.FullName;

                if (!parentPath.Equals(initialDirectory))
                {
                    matchResult = MatchIncludeInParentPath(filePath, parentPath, includeMatchType);
                }
            }

            if (matchPathExists && matchResult == null)
                return matchPath;

            return matchResult;
        }
    

开发者ID:ubisoft,项目名称:Sharpmake,代码行数:30,代码来源:AttributeParsers.cs

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

DirectoryInfo.Equals的代码示例3 - AddNonMemberItems()

    using System.IO;

        /// 
        /// Add non-member items to the hierarchy
        /// 
        private void AddNonMemberItems()
        {
            string path;

            var ignoredFolders = this.FoldersToIgnore();

            // Get a list of the folders and files in the project folder excluding those that are hidden or not
            // wanted.  Hash sets are used so that we can do case-insensitive comparisons when excluding existing
            // project items from the lists.
            HashSet folders = new HashSet(Directory.EnumerateDirectories(
                this.ProjectFolder, "*", SearchOption.AllDirectories).Where(p =>
                {
                    if(ignoredFolders.Any(folder => p.StartsWith(folder, StringComparison.OrdinalIgnoreCase)))
                        return false;

                    DirectoryInfo di = new DirectoryInfo(p);

                    return !((di.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden);
                }).Select(p => PackageUtilities.MakeRelative(this.ProjectFolder, p)),
                StringComparer.OrdinalIgnoreCase);

            HashSet files = new HashSet(Directory.EnumerateFiles(
                this.ProjectFolder, "*", SearchOption.AllDirectories).Where(f =>
                {
                    if(ignoredFolders.Any(folder => f.StartsWith(folder, StringComparison.OrdinalIgnoreCase)))
                        return false;

                    FileInfo fi = new FileInfo(f);

                    return !((fi.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden);
                }).Select(f => PackageUtilities.MakeRelative(this.ProjectFolder, f)),
                StringComparer.OrdinalIgnoreCase);

            // Remove the folders and files that are already in the project
            foreach(Microsoft.Build.Evaluation.ProjectItem item in this.BuildProject.Items)
                if(folders.Count != 0 && item.ItemType.Equals(ProjectFileConstants.Folder,
                  StringComparison.OrdinalIgnoreCase))
                {
                    path = item.EvaluatedInclude;

                    // It should be relative already but check it just in case
                    if(Path.IsPathRooted(path)) 
                        path = PackageUtilities.MakeRelative(this.ProjectFolder, path);

                    if(folders.Contains(path))
                        folders.Remove(path);
                }
                else
                    if(files.Count != 0 && this.IsItemTypeFileType(item.ItemType))
                    {
                        path = item.EvaluatedInclude;

                        // It should be relative already but check it just in case
                        if(Path.IsPathRooted(path)) 
                            path = PackageUtilities.MakeRelative(this.ProjectFolder, path);

                        if(files.Contains(path))
                            files.Remove(path);
                    }

            // Add the remaining items to the project
            this.AddNonMemberFolderItems(folders);
            this.AddNonMemberFileItems(files);
        }
    

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

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

DirectoryInfo.Equals的代码示例4 - DetectSharepoint()

    using System.IO;

		private static Task> DetectSharepoint()
		{
			using var oneDriveAccountsKey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\OneDrive\Accounts");
			if (oneDriveAccountsKey is null)
			{
				return Task.FromResult>(null);
			}

			var sharepointAccounts = new List();
			foreach (var account in oneDriveAccountsKey.GetSubKeyNames())
			{
				var accountKey = oneDriveAccountsKey.OpenSubKey(account);
				if (accountKey is null)
					continue;

				var userFolderToExcludeFromResults = (string)accountKey.GetValue("UserFolder", "");

				var sharePointParentFolders = new List();
				using (var mountPointsKey = accountKey.OpenSubKey("ScopeIdToMountPointPathCache"))
				{
					if (mountPointsKey is null)
					{
						continue;
					}

					var valueNames = mountPointsKey.GetValueNames();
					foreach (var valueName in valueNames)
					{
						var directory = (string?)mountPointsKey.GetValue(valueName, null);
						if (directory != null && !string.Equals(directory, userFolderToExcludeFromResults, StringComparison.OrdinalIgnoreCase))
						{
							var parentFolder = Directory.GetParent(directory);
							if (parentFolder != null)
								sharePointParentFolders.Add(parentFolder);
						}
					}
				}

				sharePointParentFolders.Sort((left, right) => left.FullName.CompareTo(right.FullName));

				foreach (var sharePointParentFolder in sharePointParentFolders)
				{
					string name = $"SharePoint - {sharePointParentFolder.Name}";
					if (!sharepointAccounts.Any(acc => string.Equals(acc.Name, name, StringComparison.OrdinalIgnoreCase)))
					{
						sharepointAccounts.Add(new CloudProvider(CloudProviders.OneDriveCommercial)
						{
							Name = name,
							SyncFolder = sharePointParentFolder.FullName,
						});
					}
				}
			}

			return Task.FromResult>(sharepointAccounts);
		}
    

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

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

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