This question already has an answer here:
这个问题在这里已有答案:
- CLS (clear) a single line? 3 answers
CLS(清除)单行? 3个答案
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.
是否有一个函数,在命令提示符中清除最后一行?我不是指“cls” - 它清除整个屏幕,我想删除最后一行。
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.
例如我正在搜索文件夹及其子文件夹中的文件,我想打印到cmd当前文件夹 - 但我想重写它,当文件夹更改时,不只是追加到最后。我知道,这只是一种平庸,但我感兴趣的是如何做到这一点。
5 个解决方案
#1
1
No, there is no command to do this
不,没有命令这样做
#2
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:
哪一个是最后一行?提示之上的那个?如果这就是你的意思,那么没有,没有办法只使用提示清除。如果您正在谈论以编程方式执行此操作,请尝试使用“\ r \ n”,如下所示:
print("\rNew text in the line");
#3
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.
如果您正在使用ANSI屏幕驱动程序,您只需输出“\ r”,您的新行,然后输出'ESC','[','K',它将清除到行尾。
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.
在这种情况下,您可以将所有内容填充到任意方式的79个字符,它只使用“\ r”字符,独立于ANSI驱动程序。
#4
1
Are you looking for Ctl-c?
你在寻找Ctl-c吗?
#5
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)
您可以使用括号记录前一个,然后不使用TYPE命令记录要删除的行:(这只是一个示例)
(
echo (Previous Outputs)
(This may happen as many times as needed)
) >> C:\file.txt
set /P thing=
cls
type C:\file.txt
pause
#1
1
No, there is no command to do this
不,没有命令这样做
#2
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:
哪一个是最后一行?提示之上的那个?如果这就是你的意思,那么没有,没有办法只使用提示清除。如果您正在谈论以编程方式执行此操作,请尝试使用“\ r \ n”,如下所示:
print("\rNew text in the line");
#3
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.
如果您正在使用ANSI屏幕驱动程序,您只需输出“\ r”,您的新行,然后输出'ESC','[','K',它将清除到行尾。
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.
在这种情况下,您可以将所有内容填充到任意方式的79个字符,它只使用“\ r”字符,独立于ANSI驱动程序。
#4
1
Are you looking for Ctl-c?
你在寻找Ctl-c吗?
#5
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)
您可以使用括号记录前一个,然后不使用TYPE命令记录要删除的行:(这只是一个示例)
(
echo (Previous Outputs)
(This may happen as many times as needed)
) >> C:\file.txt
set /P thing=
cls
type C:\file.txt
pause