C# DriveInfo.GetDrives的代码示例

DriveInfo.GetDrives方法的主要功能描述

通过代码示例来学习C# DriveInfo.GetDrives方法

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


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

DriveInfo.GetDrives的代码示例1 - IsSupported()

    using System.IO;

        public bool IsSupported(string normalizedEnlistmentRootPath, out string warning, out string error)
        {
            warning = null;
            error = null;

            string pathRoot = Path.GetPathRoot(normalizedEnlistmentRootPath);
            DriveInfo rootDriveInfo = DriveInfo.GetDrives().FirstOrDefault(x => x.Name == pathRoot);
            string requiredFormat = "NTFS";
            if (rootDriveInfo == null)
            {
                warning = $"Unable to ensure that '{normalizedEnlistmentRootPath}' is an {requiredFormat} volume.";
            }
            else if (!string.Equals(rootDriveInfo.DriveFormat, requiredFormat, StringComparison.OrdinalIgnoreCase))
            {
                error = $"Error: Currently only {requiredFormat} volumes are supported.  Ensure repo is located into an {requiredFormat} volume.";
                return false;
            }

            if (Common.NativeMethods.IsFeatureSupportedByVolume(
                Directory.GetDirectoryRoot(normalizedEnlistmentRootPath),
                Common.NativeMethods.FileSystemFlags.FILE_RETURNS_CLEANUP_RESULT_INFO))
            {
                return true;
            }

            error = "File system does not support features required by VFS for Git. Confirm that Windows version is at or beyond that required by VFS for Git. A one-time reboot is required on Windows Server 2016 after installing VFS for Git.";
            return false;
        }
    

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

在microsoft提供的IsSupported()方法中,该源代码示例一共有30行, 其中使用了DriveInfo.GetDrives()1次, 并且小编将这些方法高亮显示出来了,希望对您了解DriveInfo.GetDrives()有帮助。 如果您觉得有帮助的话,请帮忙点赞或转发。
该代码示例的点赞次数为3, 点赞数越大, 从某种程度说明这个示例对了解DriveInfo.GetDrives()可能更有帮助。

DriveInfo.GetDrives的代码示例2 - CheckArgs()

    using System.IO;

        // Checks the input of the args and adds defaults for empty args
        public void CheckArgs() {
            if (Directories.Count == 0) {
                Console.WriteLine("[!] No directories entered. Adding all mounted drives.");
                foreach (DriveInfo d in DriveInfo.GetDrives()) {
                    Directories.Add(d.Name);
                }
            }


            if (FileTypes.Count == 0) {
                Console.WriteLine("[!] No filetypes entered. Adding '.txt' and '.docx' as defaults.");
                foreach (string s in DefaultFileTypes) {
                    FileTypes.Add(s);
                }
            }


        }
    

开发者ID: vivami,   项目名称: SauronEye,   代码行数: 21,   代码来源: ArgumentParser.cs

在vivami提供的CheckArgs()方法中,该源代码示例一共有21行, 其中使用了DriveInfo.GetDrives()1次, 并且小编将这些方法高亮显示出来了,希望对您了解DriveInfo.GetDrives()有帮助。 如果您觉得有帮助的话,请帮忙点赞或转发。
该代码示例的点赞次数为3, 点赞数越大, 从某种程度说明这个示例对了解DriveInfo.GetDrives()可能更有帮助。

DriveInfo.GetDrives的代码示例3 - FindHtmlHelpCompiler()

    using System.IO;
        #endregion

        #region Tool location methods
        //=====================================================================

        /// 
        /// Find the HTML help compiler
        /// 
        /// This is thrown if the HTML help compiler cannot be found
        protected void FindHtmlHelpCompiler()
        {
            hhcFolder = project.HtmlHelp1xCompilerPath;

            if(hhcFolder.Length == 0)
            {
                this.ReportProgress("Searching for HTML Help 1 compiler...");

                // Check for a 64-bit process.  The tools will be in the x86 folder.  If running as a 32-bit
                // process, the folder will contain "(x86)" already if on a 64-bit OS.
                StringBuilder sb = new StringBuilder(Environment.GetFolderPath(Environment.Is64BitProcess ?
                    Environment.SpecialFolder.ProgramFilesX86 : Environment.SpecialFolder.ProgramFiles));

                sb.Append(@"\HTML Help Workshop");

                foreach(DriveInfo di in DriveInfo.GetDrives())
                {
                    if(di.DriveType == DriveType.Fixed)
                    {
                        sb[0] = di.Name[0];

                        if(Directory.Exists(sb.ToString()))
                        {
                            hhcFolder = sb.ToString();
                            break;
                        }
                    }
                }
            }

            if(hhcFolder.Length == 0 || !Directory.Exists(hhcFolder))
            {
                throw new BuilderException("BE0037", "Could not find the path to the HTML Help 1 compiler.  " +
                    "Is the HTML Help Workshop installed?  See the error number topic in the help file " +
                    "for details.\r\n");
            }

            if(hhcFolder[hhcFolder.Length - 1] != '\\')
                hhcFolder += @"\";

            this.ReportProgress("Found HTML Help 1 compiler in '{0}'", hhcFolder);
        }
    

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

在EWSoftware提供的FindHtmlHelpCompiler()方法中,该源代码示例一共有52行, 其中使用了DriveInfo.GetDrives()1次, 并且小编将这些方法高亮显示出来了,希望对您了解DriveInfo.GetDrives()有帮助。 如果您觉得有帮助的话,请帮忙点赞或转发。
该代码示例的点赞次数为3, 点赞数越大, 从某种程度说明这个示例对了解DriveInfo.GetDrives()可能更有帮助。

DriveInfo.GetDrives的代码示例4 - FindOnFixedDrives()

    using System.IO;
        #endregion

        #region Find tools
        //=====================================================================

        /// 
        /// Find a folder by searching the Program Files folders on all fixed drives
        /// 
        /// The path for which to search
        /// The path if found or an empty string if not found
        public static string FindOnFixedDrives(string path)
        {
            // Check for a 64-bit process.  The tools will be in the x86 folder.  If running as a 32-bit process,
            // the folder will contain "(x86)" already if on a 64-bit OS.
            StringBuilder sb = new StringBuilder(Environment.GetFolderPath(Environment.Is64BitProcess ?
                Environment.SpecialFolder.ProgramFilesX86 : Environment.SpecialFolder.ProgramFiles));

            sb.Append(path);

            foreach(DriveInfo di in DriveInfo.GetDrives())
                if(di.DriveType == DriveType.Fixed)
                {
                    sb[0] = di.Name[0];

                    if(Directory.Exists(sb.ToString()))
                        return sb.ToString();
                }

            return String.Empty;
        }
    

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

在EWSoftware提供的FindOnFixedDrives()方法中,该源代码示例一共有31行, 其中使用了DriveInfo.GetDrives()1次, 并且小编将这些方法高亮显示出来了,希望对您了解DriveInfo.GetDrives()有帮助。 如果您觉得有帮助的话,请帮忙点赞或转发。
该代码示例的点赞次数为3, 点赞数越大, 从某种程度说明这个示例对了解DriveInfo.GetDrives()可能更有帮助。

DriveInfo.GetDrives的代码示例5 - GetDrivesAsync()

    using System.IO;

		public async IAsyncEnumerable GetDrivesAsync()
		{
			var list = DriveInfo.GetDrives();
			var googleDrivePath = App.AppModel.GoogleDrivePath;
			var pCloudDrivePath = App.AppModel.PCloudDrivePath;

			foreach (var drive in list)
			{
				var res = await FilesystemTasks.Wrap(() => StorageFolder.GetFolderFromPathAsync(drive.Name).AsTask());
				if (res.ErrorCode is FileSystemStatusCode.Unauthorized)
				{
					App.Logger.LogWarning($"{res.ErrorCode}: Attempting to add the device, {drive.Name},"
						+ " failed at the StorageFolder initialization step. This device will be ignored.");
					continue;
				}
				else if (!res)
				{
					App.Logger.LogWarning($"{res.ErrorCode}: Attempting to add the device, {drive.Name},"
						+ " failed at the StorageFolder initialization step. This device will be ignored.");
					continue;
				}

				using var thumbnail = await DriveHelpers.GetThumbnailAsync(res.Result);
				var type = DriveHelpers.GetDriveType(drive);
				var label = DriveHelpers.GetExtendedDriveLabel(drive);
				var driveItem = await DriveItem.CreateFromPropertiesAsync(res.Result, drive.Name.TrimEnd('\\'), label, type, thumbnail);

				// Don't add here because Google Drive is already displayed under cloud drives
				if (drive.Name == googleDrivePath || drive.Name == pCloudDrivePath)
					continue;

				App.Logger.LogInformation($"Drive added: {driveItem.Path}, {driveItem.Type}");

				yield return driveItem;
			}
		}
    

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

在files-community提供的GetDrivesAsync()方法中,该源代码示例一共有38行, 其中使用了DriveInfo.GetDrives()1次, 并且小编将这些方法高亮显示出来了,希望对您了解DriveInfo.GetDrives()有帮助。 如果您觉得有帮助的话,请帮忙点赞或转发。
该代码示例的点赞次数为3, 点赞数越大, 从某种程度说明这个示例对了解DriveInfo.GetDrives()可能更有帮助。

DriveInfo.GetDrives的代码示例6 - OnCreate()

    using System.IO;
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);

            var path = ".".GetFullPath();
            var driveInfo = DriveInfo.GetDrives().FirstOrDefault(e => path.StartsWithIgnoreCase(e.Name));

            var deviceId = Android.Provider.Settings.Secure.GetString(Application.Context.ContentResolver, Android.Provider.Settings.Secure.AndroidId);

            var device = DeviceInfo.Model;
            var dic = new Dictionary();
            foreach (var item in typeof(DeviceInfo).GetProperties())
            {
                dic[item.Name] = item.GetValue(device);
            }
            var js = dic.ToJson(true);

            // 设置入口程序集
            var asm = Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly();
            if (asm != null) AssemblyX.Entry = AssemblyX.Create(asm);

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
            LoadApplication(new App());
        }
    

开发者ID: NewLifeX,   项目名称: X,   代码行数: 29,   代码来源: MainActivity.cs

在NewLifeX提供的OnCreate()方法中,该源代码示例一共有29行, 其中使用了DriveInfo.GetDrives()1次, 并且小编将这些方法高亮显示出来了,希望对您了解DriveInfo.GetDrives()有帮助。 如果您觉得有帮助的话,请帮忙点赞或转发。
该代码示例的点赞次数为3, 点赞数越大, 从某种程度说明这个示例对了解DriveInfo.GetDrives()可能更有帮助。

DriveInfo.GetDrives()方法的常见问题及解答

C#中DriveInfo.GetDrives()的常见错误类型及注意事项

DriveInfo.GetDrives的错误类型有很多, 这里就不一一阐述了,本文只列出一些常见的代码示例供参考,大家可以看一下代码中Catch语句中是否有常见的错误捕获及处理。

C#中DriveInfo.GetDrives()的构造函数有哪些

DriveInfo.GetDrives构造函数功能基本类似,只是参数不同; 目前主流的集成开发环境都已经带智能提醒了,如:Visual Studio; 大家可以非常轻松的通过Visual Studio中的智能提醒,了解对应构造函数的用法。

如何使用ChartGPT写一段DriveInfo.GetDrives的代码

你可以在ChartGPT中输入如下的指令:"提供一个如何使用DriveInfo.GetDrives的C#代码示例"
ChartGPT写出的代码和本文中的小编提供的代码的区别。 ChartGPT发展到现在已经非常聪明了,但需要使用这提供非常专业的问题,才可能有比较好的源代码示例; 而本文中, 小编已经帮您列出来基本所有类和所有方法的使用示例, 而且这些示例基本都是一些网络大佬提供的源码,可以更方便的供一些开发菜鸟或者资深开发参考和学习。

DriveInfo.GetDrives所在的类及名称空间

DriveInfo.GetDrives是System.IO下的方法。

DriveInfo.GetDrives怎么使用?

DriveInfo.GetDrives使用上比较简单,可以参考MSDN中的帮助文档,也参考本文中提供的7个使用示例。

DriveInfo.GetDrives菜鸟教程

对于菜鸟来说,本文中提供的7个DriveInfo.GetDrives写法都将非常直观的帮您掌握DriveInfo.GetDrives的用法,是一个不错的参考教程。

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