如何在外部硬盘中保存文件 [英] How to save a file in external hard disk

查看:88
本文介绍了如何在外部硬盘中保存文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想保存一个名称意味着卷标的文件。

问题是我想用高清名称保存外部硬盘中的文件。



使用代码获取外部硬盘名称的名称:



i want to save a file with there name means volume label.
the problem is that i want to save a file in my external hard disk with hd name.

using the code it get the name of external hard disk name:

 DriveInfo[] drives = DriveInfo.GetDrives();
List<string> removables = new List<string>();

foreach (DriveInfo d in drives)
{
    if (d.IsReady == true)
    {
        if (d.DriveType == DriveType.Removable)
        {
            removables.Add(d.VolumeLabel);
            drpExternalDrive.Items.Add(d.VolumeLabel);
        }
    }
}

假设extnl高清名称是Nayuma2013.now我想用路径Nayuma2013 \Video\NayumaVideo保存它。

那么怎么做。

当我使用这段代码然后我收到错误



lets suppose extnl hd name is Nayuma2013.now i want to save it with path "Nayuma2013\Video\NayumaVideo".
So how to do this.
when i use this code then i get error

string adada = "Nayuma2013:\\Video\\NayumaVideo";
if (!Directory.Exists(adada))
{
    Directory.CreateDirectory(adada);
}



文件格式路径不正确。


file format path is not correct.

推荐答案

这不是一个有效的目录名称。如果某个驱动器已经有有效的 DriveInfo d ,则可以使用 System.IO.DriveInfo.RootDirectory property:

This is not a valid directory name. If you are already have valid DriveInfo d for some drive, you can get a valid file name by using System.IO.DriveInfo.RootDirectory property:
string fileName = //... simple file name
fileName = string.Format(
    "{0}{1}{2}",
    d.RootDirectory,
    System.IO.Path.PathSeparator,
    fileName);

请参阅:http://msdn.microsoft.com/en-us/library/system.io.driveinfo.rootdirectory%28v=vs.110% 29.aspx [ ^ ]。



如果你需要某个子目录中的文件ries,首先使用 System.IO.Directory.CreateDirectory 创建它们:

http://msdn.microsoft.com/en-us/library/system.io.directory.aspx [ ^ ]。



-SA

Please see: http://msdn.microsoft.com/en-us/library/system.io.driveinfo.rootdirectory%28v=vs.110%29.aspx[^].

If you need the file in some subdirectories, first create them under the root using System.IO.Directory.CreateDirectory:
http://msdn.microsoft.com/en-us/library/system.io.directory.aspx[^].

—SA


这篇关于如何在外部硬盘中保存文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆