资源简介

C# winform文件复制 带进度条 类似于windows

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace CopyFiles
{
    //http://www.pinvoke.net/default.aspx/kernel32.CopyFileEx
    /// 
    /// Copies a list of files or a directory tree to a destination
    /// 
    /// Support for GUI is implamented by the ICopyFilesDiag interface
    /// and passed to the class in the copy() method.
    /// 

    public class CopyFiles
    {

        // Variables
        private List files = new List();
        private List newFilenames = new List();
        private List filesCopied = new List();
        private Int32 totalFiles = 0;
        private Int32 totalFilesCopied = 0;
        private String destinationDir = ““;
        private String sourceDir = ““;
        private String currentFilename;
        private Boolean cancel = false;
        private IAsyncResult CopyResult;
        private DEL_CopyFiles delCopy;
        private ICopyFilesDiag digWindow;

        // Structurs
        public struct ST_CopyFileDetails
        {

            String OriginalURI;
            String NewURI;

            // Constructor
            public ST_CopyFileDetails(String FromURI String ToURI)
            {
                OriginalURI = FromURI;
                NewURI = ToURI;
            }

        }

        // Enums
        // These Enums are used for the windows CopyFileEx function
        [Flags]
        private enum CopyFileFlags : uint
        {
            COPY_FILE_FAIL_IF_EXISTS = 0x00000001
            COPY_FILE_RESTARTABLE = 0x00000002
            COPY_FILE_OPEN_SOURCE_FOR_WRITE = 0x00000004
            COPY_FILE_ALLOW_DECRYPTED_DESTINATION = 0x00000008
        }
        private enum CopyProgressResult : uint
        {
            PROGRESS_CONTINUE = 0
            PROGRESS_CANCEL = 1
            PROGRESS_STOP = 2
            PROGRESS_QUIET = 3
        }
        private enum CopyProgressCallbackReason : uint
        {
            CALLBACK_CHUNK_FINISHED = 0x00000000
            CALLBACK_STREAM_SWITCH = 0x00000001
        }

        // Events
        public event DEL_copyComplete EV_copyComplete;
        public event DEL_copyCanceled EV_copyCanceled;

        // Delegates
        private delegate CopyProgressResult CopyProgressRoutine(Int64 TotalFileSize Int64 TotalBytesTransferred Int64 StreamSize Int64 StreamBytesTransferred UInt32 dwStreamNumber CopyProgressCallbackReason dwCallbackReason IntPtr hSourceFile IntPtr hDestinationFile IntPtr lpData);
        private delegate CopyProgressResult DEL_CopyProgressHandler(Int64 total Int64 transferred Int64 streamSize Int64 StreamByteTrans UInt32 dwStreamNumber CopyProgressCallbackReason reason IntPtr hSourceFile IntPtr hDestinationFile IntPtr lpData);
        private delegate void DEL_CopyFiles();
 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件          0  2009-03-05 17:43  CopyFiles\Copy Test Folder\Bob.txt

     文件          0  2009-03-05 17:43  CopyFiles\Copy Test Folder\test.txt

     文件          0  2009-03-05 17:43  CopyFiles\Copy Test Folder\Test1\B.o.b.Trev..txt

     文件          0  2009-03-05 17:43  CopyFiles\Copy Test Folder\Test1\Bob.Trev.txt

     文件          0  2009-03-05 17:43  CopyFiles\Copy Test Folder\Test1\test.txt

     文件          0  2009-03-05 17:43  CopyFiles\Copy Test Folder\Test2\Bob.Trev.txt

     文件          0  2009-03-05 17:43  CopyFiles\Copy Test Folder\Test2\test.txt

     文件          0  2009-03-05 17:43  CopyFiles\Copy Test Folder\Test3\B.o.b.Trev..txt

     文件          0  2009-03-05 17:43  CopyFiles\Copy Test Folder\Test3\Bob.Trev.txt

     文件          0  2009-03-05 17:43  CopyFiles\Copy Test Folder\Test3\test.txt

     文件          0  2009-03-05 17:43  CopyFiles\Copy Test Folder\Test4\Bob.Trev.txt

     文件          0  2009-03-05 17:43  CopyFiles\Copy Test Folder\Test4\test.txt

     文件      16967  2009-05-22 09:34  CopyFiles\CopyFiles\Backup\CopyFiles\CopyFiles.cs

     文件       3015  2009-05-22 09:38  CopyFiles\CopyFiles\Backup\CopyFiles\CopyFiles.csproj

     文件       1673  2009-05-22 09:45  CopyFiles\CopyFiles\Backup\CopyFiles\DIA_CopyFiles.cs

     文件       4432  2009-05-22 09:44  CopyFiles\CopyFiles\Backup\CopyFiles\DIA_CopyFiles.Designer.cs

     文件       5814  2009-05-22 09:44  CopyFiles\CopyFiles\Backup\CopyFiles\DIA_CopyFiles.resx

     文件       1462  2009-05-22 09:33  CopyFiles\CopyFiles\Backup\CopyFiles\Properties\AssemblyInfo.cs

     文件       1395  2009-05-22 09:40  CopyFiles\CopyFiles\Backup\CopyFiles.sln

     文件       2543  2009-05-22 09:52  CopyFiles\CopyFiles\Backup\TestCopy\Form1.cs

     文件       2116  2009-05-22 09:40  CopyFiles\CopyFiles\Backup\TestCopy\Form1.Designer.cs

     文件       5814  2009-05-22 09:40  CopyFiles\CopyFiles\Backup\TestCopy\Form1.resx

     文件        500  2009-05-22 09:39  CopyFiles\CopyFiles\Backup\TestCopy\Program.cs

     文件       1460  2009-05-22 09:39  CopyFiles\CopyFiles\Backup\TestCopy\Properties\AssemblyInfo.cs

     文件       2845  2009-05-22 09:39  CopyFiles\CopyFiles\Backup\TestCopy\Properties\Resources.Designer.cs

     文件       5612  2009-05-22 09:39  CopyFiles\CopyFiles\Backup\TestCopy\Properties\Resources.resx

     文件       1093  2009-05-22 09:39  CopyFiles\CopyFiles\Backup\TestCopy\Properties\Settings.Designer.cs

     文件        249  2009-05-22 09:39  CopyFiles\CopyFiles\Backup\TestCopy\Properties\Settings.settings

     文件       3942  2009-05-22 09:52  CopyFiles\CopyFiles\Backup\TestCopy\TestCopy.csproj

     文件      17920  2015-09-25 17:00  CopyFiles\CopyFiles\CopyFiles\bin\Debug\CopyFiles.dll

............此处省略75个文件信息

评论

共有 条评论