0

I have a Windows 10 batch file that runs ffprobe on all files in a directory. Each file name is displayed on the screen on a specific line. When the next file is processed the previous file name is erased and the next file name is written on the same line (so the file names don't run down the screen). I've noticed that for file names greater than 120 characters in length the VT100 escape sequences I'm using break to some extent. Here's the portion of my code that is applicable:

echo Checking files......

for %%a in ("*.*") do (
    set filename=%%a
    for /f "tokens=1,2,3 delims=," %%a in ('ffprobe [...]') do (
        set codec=%%b
    )

    set /p="%ESC%[1G%ESC%[2K%%~a"<nul
)

set /p="%ESC%[A%ESC%[1G%ESC%[2K"<nul

(I've edited the ffprobe portion just so everything is more readable. ffprobe has nothing to do with the issue I'm seeing).

The escape sequences normally result in the display of the current file name, once ffprobe is finished with that file the cursor is moved to the 1st position on that line and the line (file name) is deleted. After the for loop the line is advanced down so sequence [A is used to move the line back up one so all the files display on the same line.

This has been working fine for months, but I just noticed on a very long file name that was 124 characters the file name is not erased and the next file name is displayed on the following line and the batch file runs correctly from there with that long file name remaining on the screen and the rest of my script runs below it. The way things should work is that each file name is deleted from the screen and none should be shown once this section of the batch file completes.

I deleted characters in the file name to see what number of characters would result in the escape sequences processing correctly and apparently there's a 120 character max.

Is this known behavior? This really isn't a major problem, but it is kind of annoying. Is there anyway to get around this?

gregm
  • 157
  • 6
  • 20
  • The console window probably isn't wide enough to display 124 characters on a single line. So the text spills over to the next line. The only practical workaround is to make the window bigger, press Alt+Space > Properties > Layout. Using a tail utility is likely to be the better approach. – Hans Passant Sep 21 '19 at 16:35
  • @HansPassant that was it. Thanks. – gregm Sep 21 '19 at 17:15
  • You could use the `cls` command or the escape sequence for clear screen and home. Then you won't have to care about the width of the console window. – jwdonahue Sep 21 '19 at 18:25
  • @jwdonahue cls is not a good option for this because there are other things on the screen that need to be there that would get removed. I have a subroutine that I wrote in an earlier version that cuts off file names at a certain number of characters that I can go back to using on really long file names. – gregm Sep 21 '19 at 23:59

0 Answers0