Tell me how to implement such a thing in the console: there is a disk check in the command line, there is one line and then a colon, and constantly different file names are written to the file names, but the line itself does not change. And when I also want to do, then I constantly go down the line, and it turns out for each file a new line. How to make everything on one line only, the names changed?
1 answer
You probably wanted something like this:
var d = Directory.GetFiles(@"c:\Games\Battlefield 3\Data\"); foreach (var s in d) { Console.Clear(); Console.WriteLine(s); Thread.Sleep(50); }
PS Author, do not be offended, but before programming, learn Russian - write as illiterate shkolota
- @DreamChild However, you are a cruel child. Console.Clear () ... To not peeked, what was on the screen before? - alexlz
- maybe I did not understand something from the author’s disjointed speech, but he seemed to want all this magnificence to be displayed on one line. I will even quote the immortal words of the author: "I constantly go down the line, and it turns out for each file a new line, and how to make everything on one line only the names change?" Or am I mistaken?)) - DreamChild
- one“No, everything is right, everything is right” (c) T. Saakhov. Yes, file names are displayed in one line, but. This is the only line on the screen. All other Clear () pochikal. Would you like it yourself? In the vehicle it turns out that it displays in the last line, translates the line and the screen scrolls up. And if so? var p = 1; foreach (var s in d) {Console.Write ("". PadRight (p)); Console.Write ('\ r'); Console.Write (s); Thread.Sleep (50); Console.Write ('\ r'); p = s.Length; } - alexlz
- I just did not bother with this, considering that the author is most likely an educational task from the category of "Hello World" (although, perhaps, I am mistaken). But your answer is definitely better - DreamChild
|
\r
character and repeat the output of the string. Just remember to flush (usually console buffering per line) - alexlz