Exemplo n.º 1
0
        //拷贝循环
        private void copycircle()
        {
            if (topathnum < topaths.Length)
            {
                totalSize = 0;
                position  = 0;
                topath    = topaths[topathnum];
                topath    = FunctionUtils.AutoCreateFolder(topath);
                if (topath != null)
                {
                    try {
                        var fs = new FileStream(frompath, FileMode.Open, FileAccess.Read);
                        totalSize = (int)fs.Length;
                        stream    = fs;
                    } catch (Exception) {
                        MessageBox.Show("读取文件失败:" + frompath, "提示");
                        return;
                    }

                    if (File.Exists(topaths[topathnum] + "/" + filename))
                    {
                        File.Delete(topaths[topathnum] + "/" + filename);
                    }
                    if (totalSize < BUFFER_SIZE)
                    {
                        BUFFER_SIZE = totalSize;
                    }
                    buffer = new byte[BUFFER_SIZE];
                    stream.BeginRead(buffer, 0, BUFFER_SIZE, new AsyncCallback(AsyncCopyFile), null);
                }
                else
                {
                    MessageBox.Show("文件路径不存在,尝试创建路径失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    topathnum++;
                    copycircle();
                }
            }
        }