如何在一个单循环中更新三行 [英] How Do I Update Three Lines In One Single Loop

查看:72
本文介绍了如何在一个单循环中更新三行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示当前的进度..

所以,在第一行它应显示当前文件名

第二行显示当前文件号

第三名应该显示完成%



所以我做了这个小程序



i want to display the current progress..
So, In the first line it should display the current file Name
second line to display the current file No.
third should display completed %

So i made this little program

string[] files = Directory.GetFiles(sourceDirectory, "*", SearchOption.AllDirectories);
int totalfiles = Directory.GetFiles(sourceDirectory, "*.*", SearchOption.AllDirectories).Length;
Console.WriteLine("{0} File(s) Found.", totalfiles); //For Example Found 1000 Files
int num = 1;
double percent = 0.0;
foreach (string file in files)
{
Console.Write("\rCurrent File Name :- {0}",Path.GetFileName(file));
percent = Convert.ToInt32(((double)num / (double)totalfiles) * (double)100);
Console.Write("\r{0}/{1} Files Completed", num++, totalfiles);
Console.Write("\r{0}% Completed", (num / totalfiles) * 100);
Thread.Sleep(10);
//DoingSomeWork();
}





但这并没有正确显示我想要的



看到这个输出图像



如果重叠每行...

i知道我不是在写 \ n或WriteLine因为这会每次生成新行

所以该怎么办?

请帮助



抱歉我的英文不好,如果问题标题不正确也很抱歉..



But This is not displaying it correctly as i wanted

SeeThisOutputImage

it if overlapping everyline..
i know that i am not writing "\n" or "WriteLine" as this will generate the new line every time
so what should i do??
Please Help

Sorry for my bad English and also sorry if the question title is not correct..

推荐答案

我的猜测是,你是寻找
Console.SetCursorPosition

进一步阅读这个 [ ^ ]也会有所帮助。

for further reading maybe this[^] would also help.


这篇关于如何在一个单循环中更新三行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆