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


C# DriveInfo.ToString方法代码示例

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


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

示例1: Main

        public static int Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("usage: makeiso [drive] [file]");
                return 1;
            }

            var drive = new DriveInfo(args[0]);

            if (drive.DriveType != DriveType.CDRom)
            {
                Console.Error.WriteLine("Invalid drive letter.");
                return 2;
            }

            try
            {
                using (var inputFileHandle = CreateFile(@"\\.\" + drive.ToString().TrimEnd('\\'), GENERIC_READ, FILE_SHARE_READ, IntPtr.Zero, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, 0))
                {
                    if (inputFileHandle.IsInvalid)
                    {
                        Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
                    }

                    using (var inputStream = new FileStream(inputFileHandle, FileAccess.Read))
                    {
                        using (var outputStream = new FileStream(args[1], FileMode.CreateNew))
                        {
                            inputStream.CopyTo(outputStream);
                        }
                    }
                }

                return 0;
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
                return 1;
            }
        }
开发者ID:jasonmalinowski,项目名称:makeiso,代码行数:42,代码来源:Program.cs

示例2: GenerateDriveNode

        /// <summary>
        /// Generates <see cref="TreeViewItem"/> for drive info.
        /// </summary>
        /// <param name="drive"></param>
        /// <returns></returns>
        private static TreeViewItem GenerateDriveNode(DriveInfo drive)
        {
            var item = new TreeViewItem
            {
                Tag = drive,
                Header = drive.ToString()
            };

            item.Items.Add("*");
            return item;
        }
开发者ID:kingofthebongo2008,项目名称:maxymillion,代码行数:16,代码来源:ExplorerTreeView.cs

示例3: Do

 public bool Do(DriveInfo drive)
 {
     bool result = true;
     foreach (CopyJob cj in jobs)
     {
         result = result & cj.Do(drive.ToString());
         if (pb.Value == pb.Maximum)
             pb.Value = 1;
         pb.Value++;
     }
     return result;
 }
开发者ID:reisi007,项目名称:LibO-Tankstelle,代码行数:12,代码来源:Form1.cs

示例4: TestInvalidDiskProperties

        public void TestInvalidDiskProperties()
        {
            string invalidDriveName = GetInvalidDriveLettersOnMachine().First().ToString();
            var invalidDrive = new DriveInfo(invalidDriveName);

            Assert.Throws<DriveNotFoundException>(() => invalidDrive.AvailableFreeSpace);
            Assert.Throws<DriveNotFoundException>(() => invalidDrive.DriveFormat);
            Assert.Equal(DriveType.NoRootDirectory, invalidDrive.DriveType);
            Assert.False(invalidDrive.IsReady);
            Assert.Equal(invalidDriveName + ":\\", invalidDrive.Name);
            Assert.Equal(invalidDriveName + ":\\", invalidDrive.ToString());
            Assert.Equal(invalidDriveName + ":\\", invalidDrive.RootDirectory.FullName);
            Assert.Throws<DriveNotFoundException>(() => invalidDrive.TotalFreeSpace);
            Assert.Throws<DriveNotFoundException>(() => invalidDrive.TotalSize);
            Assert.Throws<DriveNotFoundException>(() => invalidDrive.VolumeLabel);
            Assert.Throws<DriveNotFoundException>(() => invalidDrive.VolumeLabel = null);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:17,代码来源:DriveInfo.Windows.Tests.cs

示例5: Decrypt


//.........这里部分代码省略.........
              FileNum = -1;
            }
            //-----------------------------------
            // ディレクトリ・トラバーサル対策
            // Directory traversal countermeasures
            if (OutputFileData[0].IndexOf(@"..\") >= 0)
            {
              fDirectoryTraversal = true;
              InvalidFilePath = OutputFileData[0];
            }

            //-----------------------------------
            // Parent folder is not created.
            //
            if (_fNoParentFolder == true)
            {
              if (FileNum == 0)
              {
            if(FilePathSplits.Length > 2)  // ルートディレクトリ(ex. 0:G:\Test.txt)
            {
              ParentFolder = FilePathSplits[2];
            }
            else
            {
              ParentFolder = FilePathSplits[1];
            }
              }
              else
              {
            if (FilePathSplits.Length > 2)  // ルートディレクトリ
            {
              StringBuilder sb = new StringBuilder(FilePathSplits[2]);
              len = ParentFolder.Length;
              FilePathSplits[2] = sb.Replace(ParentFolder, "", 0, len).ToString();
            }
            else
            {
              StringBuilder sb = new StringBuilder(FilePathSplits[1]);
              len = ParentFolder.Length;
              FilePathSplits[1] = sb.Replace(ParentFolder, "", 0, len).ToString();
            }
              }
            }

            //-----------------------------------
            // File path
            //
            string OutFilePath = "";
            if (_fSalvageIntoSameDirectory == true) // Salvage mode?
            {
              OutFilePath = Path.Combine(OutDirPath, Path.GetFileName(FilePathSplits[1]));
            }
            else
            {
              if(FilePathSplits.Length > 2)
              {
            OutFilePath = Path.Combine(OutDirPath, FilePathSplits[2]);
              }
              else
              {
            OutFilePath = Path.Combine(OutDirPath, FilePathSplits[1]);
              }
            }
            fd.FilePath = OutFilePath;

            //-----------------------------------
开发者ID:hibara,项目名称:AttacheCase3,代码行数:67,代码来源:FileDecrypt3.cs


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