例如:这个图片的名字:hua.jpg,但是我不知道这张图片具体放到什么文件夹里了,怎么用C#把这张图片的路径找出来,找出来后,把这张图片剪切到E盘中?
跪求大神指点,请把代码写出来哈。

解决方案 »

  1.   

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Text;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                foreach (var item in DriveInfo.GetDrives())
                {
                    if (item.DriveType == DriveType.Fixed) //只找硬盘
                    {
                        foreach (var file in item.RootDirectory.GetFiles("hua.jpg", SearchOption.AllDirectories))
                        {
                            file.CopyTo("e:\\hua.jpg");
                            break;
                        }
                    }
                }
            }
        }
    }
      

  2.   

    谢谢哈,但是你给的代码有点问题啊,调试时出现:未处理的“System.UnauthorizedAccessException”类型的异常出现在 mscorlib.dll 中。其他信息: 对路径“C:\Windows\System32\LogFiles\WMI\RtBackup”的访问被拒绝。
       怎么回事?