C# 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

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

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

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

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

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

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

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

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

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

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

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

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