本文整理汇总了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;
}
}
示例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;
}
示例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;
}
示例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);
}
示例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;
//-----------------------------------