views:

761

answers:

4

Hello

I have maybe dumb question - is there a function, that clears last line in command prompt? I dont mean "cls" - it clears the whole sreen, I want to delete just the last line.

e.g. I am searching for a file in a folder and its subfolders and I want to print to cmd current folder - but I want to rewrite it, when the folder changes, not just append to the end. I know, this is just a banality, but I am interested how could be it done.

TYA

+3  A: 

Which one is that last line?
The one just above the prompt?
If that's what you mean then no, there is no way to clear just that using the prompt. If you're talking about doing it programatically, try using "\r" like so:

print("\rNew text in the line");
shoosh
I edited my post to make it clear.
Dungeo
+1  A: 

No, there is no command to do this

Neal Donnan
unfortunately, you are probably right :-\
Dungeo
+1  A: 

If you're using the ANSI screen drivers, you can simply output "\r", your new line, then 'ESC', '[', 'K' which will clear to the end of the line.

But one thing to watch out for, you should limit your output length to the expected screen width so the lines don't wrap, such as

c:\directory\really_big_name_too_long_..._so_Ive_put_some_ellipses_in.txt

In which case, you can probably just pad everything to 79 characters any way and it'll work with just the "\r" character, independent of ANSI driver.

paxdiablo
+1  A: 

Are you looking for Ctl-c?

Keng