问个C#文件夹处理问题,希望高手回答下,感激不尽

一个文件夹里面有一个子文件夹和一个C#文件,子文件夹里面有一些文件,各种类型都有,我想实现点击C#文件的按钮,将子文件里面的内容复制到和C#文件同一目录!其详细代码,谢谢... 一个文件夹里面有一个子文件夹和一个C#文件,子文件夹里面有一些文件,各种类型都有,我想实现点击C#文件的按钮,将子文件里面的内容复制到和C#文件同一目录!

其详细代码,谢谢了
展开
 我来答
百百mp3
2013-05-26 · TA获得超过854个赞
知道小有建树答主
回答量:901
采纳率:90%
帮助的人:541万
展开全部
string[] a = System.IO.Directory.GetFiles("/home/cxn/桌面/background");
foreach(str in a){
System.IO.File.Copy(str,
System.Windows.Forms.Application.StartupPath + "\\" +
System.IO.Path.GetFileName(str));
}
jiangshunmin
2013-05-26 · TA获得超过2053个赞
知道小有建树答主
回答量:736
采纳率:0%
帮助的人:490万
展开全部
使用
System.IO.Directory
System.IO.DirectoryInfo
System.IO.File
System.IO.FileInfo
的相关方法来完成!

简例:
string[] fileList =System.IO.Directory.GetFiles(DirPath);
//DirPath 子文件夹路径
foreach (string file in fileList)
 {
System.IO.File.Copy(file, Path + System.IO.Path.GetFileName(file),true);
//Path 目标文件夹路径 true 覆盖同名文件
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
syuesw
2013-05-26 · 超过37用户采纳过TA的回答
知道小有建树答主
回答量:75
采纳率:0%
帮助的人:98.2万
展开全部
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FileCopy
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                StartCopy();
            }
            catch (Exception ex)
            {
                ShowMessage("复制时发生错误:");
                ShowMessage(ex.Message, true);
            }
        }
        static void StartCopy()
        {
            //取得程序所在目录。
            String appDir = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            //取得当前目录里面的子文件夹。
            String[] childDir = Directory.GetDirectories(appDir);
            if (childDir.Length == 0)
            {
                ShowMessage("当前目录没有子文件夹。", true);
                return;
            }
            else if (childDir.Length > 0)
            {
                ShowMessage("当前目录中的子文件夹超过一个。", true);
                return;
            }
            String[] files = Directory.GetFiles(childDir[0], "*", SearchOption.AllDirectories);
            ShowMessage(String.Format("共找到{0}个文件。", files.Length));
            Int32 fail = 0;
            Int32 success = 0;
            foreach (String file in files)
            {
                String fileName = Path.GetFileName(file);
                String destPath = Path.Combine(appDir, fileName);
                if (File.Exists(destPath))
                {
                    ShowMessage(String.Format("目标目录已经存在同名文件“{0}”,跳过。", fileName));
                    fail++;
                }
                else
                {
                    ShowMessage(String.Format("正在复制文件“{0}”……", file));
                    File.Copy(file, destPath);
                    success++;
                }
            }
            ShowMessage(String.Format("复制完成,成功{0}个,失败{1}个。", success, fail), true);
        }
        static void ShowMessage(String message)
        {
            ShowMessage(message, false);
        }
        static void ShowMessage(String message, Boolean pause)
        {
            Console.WriteLine(message);
            if (pause)
            {
                Console.WriteLine("按任意键继续……");
                Console.ReadKey();
            }
        }
    }
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式