本文介绍了更新c#console中的进度百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在c#控制台中复制和粘贴进度的百分比进行更新



i写这个,但这不是很完美..它只显示100完全复制文件时的百分比



how do i make a update in percentage of copy and paste progress in c# console

i write this but this is not working perfectly..it only shows the 100% when the file is full copied

string fileName = @"abc.mp4";
string sourcePath = @"C:\test\source";
string targetPath = @"C:\test\copy";

string sourceFile = Path.Combine(sourcePath, fileName);
string destFile = Path.Combine(targetPath, fileName);

if (!Directory.Exists(targetPath))
{
     Directory.CreateDirectory(targetPath);
}

Console.WriteLine("Coping a File Started at {0}", DateTime.Now);

FileInfo file = new FileInfo(sourcePath.ToString() + "\\" + fileName.ToString());

Console.WriteLine("The File Size is {0} MB", ((file.Length)/1024)/1024);

FileInfo sourcesize = new FileInfo(sourcePath.ToString() + "\\" + fileName.ToString());
            
FileInfo destsize = new FileInfo(targetPath.ToString() + "\\" + fileName.ToString());

            double si = 0.0;

            while (si != 100)
                {
                    File.Copy(sourceFile, destFile, true);

                    si = (destsize.Length / sourcesize.Length) * 100;

                    Console.Write("{0} % Completed", si);
                }







现在我想要的是它应该在复制时更新百分比文件



请帮助




now i want is that it should update the percent while it is copying the file

please help

推荐答案


这篇关于更新c#console中的进度百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 09:19