6

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.

Dungeo
  • 177
  • 2
  • 7
  • 16

5 Answers5

4

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
  • 76,898
  • 55
  • 205
  • 325
4

Are you looking for Ctl-c?

Keng
  • 52,011
  • 32
  • 81
  • 111
2

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
  • 854,327
  • 234
  • 1,573
  • 1,953
1

You Could use brackets to record the previous, then not record the line you want to delete using the TYPE command: (This is just an example)

(
echo (Previous Outputs)
(This may happen as many times as needed)
) >> C:\file.txt
set /P thing=
cls
type C:\file.txt
pause
1

No, there is no command to do this

Neal Donnan
  • 1,733
  • 1
  • 13
  • 18