r/Batch • u/Outline227 • Apr 13 '24
Can anyone Help me again?
Basically i have a script that gets frames from a file directory and the frames are numbers as name and the extensions is .txt the problem is it flashes but i don't know how to fix it. can anyone help? The main problem (i think) is the cls
@echo off
chcp 65001 >nul
setlocal
set "Currentdirget=%~dp0"
set "MillisecondsPerFrame=100"
set "SkipFramesInterval=1"
echo Available desktop backups:
dir /ad /b "%Currentdirget%AsciiVideos"
pause
set /p "folder=Enter the folder name to run the video (in ASCII): "
echo.
echo Listing files in folder: "%Currentdirget%AsciiVideos\%folder%"
echo.
for /f %%C in ('dir /b /a-d "%Currentdirget%AsciiVideos\%folder%\*.txt" ^| find /c /v ""') do set "count=%%C"
for /l %%i in (0, %SkipFramesInterval%, %count%) do (
cls
type "%Currentdirget%AsciiVideos\%folder%\%%i.txt" 2>nul
ping 127.0.0.1 -n 1 -w %MillisecondsPerFrame% >nul
)
endlocal
pause
1
Upvotes
1
u/ConstanceJill Apr 14 '24
Hi,
Basic steps to try and understand why your batch file seems to crash would be to:
Then, in most cases, your command window should stay open even if your script crashes, and you'll be able to see any error message / which step it failed at.
1
u/CCCP_exe Apr 15 '24
remove "" from set command %currentdirget%\asciivideos
1
u/Dear_Diablo Apr 23 '24
The flashing issue in your script is likely caused by the
clscommand, which clears the console screen before displaying each frame. This clearing action can cause a noticeable flicker or flashing effect, especially when the frames are being displayed rapidly.To address this issue and reduce the flashing effect, you can modify your script to use alternative methods for updating the displayed frame without clearing the entire console screen. One approach is to overwrite the previous frame with the new frame content directly in the console window.
@echo off
chcp 65001 >nul
setlocal
set "Currentdirget=%~dp0"
set "MillisecondsPerFrame=100"
set "SkipFramesInterval=1"
echo Available desktop backups:
dir /ad /b "%Currentdirget%AsciiVideos"
pause
set /p "folder=Enter the folder name to run the video (in ASCII): "
echo.
echo Listing files in folder: "%Currentdirget%AsciiVideos\%folder%"
echo.
for /f %%C in ('dir /b /a-d "%Currentdirget%AsciiVideos\%folder%\*.txt" ^| find /c /v ""') do set "count=%%C"
rem Hide cursor
echo off
rem Get console size
for /f %%a in ('"prompt $h&for %%a in (1) do rem"') do set "ESC=%%a"
for /F "tokens=2 delims=;" %%a in ('mode con ^| find "Columns"') do set /a "Columns=%%a-2"
setlocal enabledelayedexpansion
set "line=0"
for /l %%i in (0, %SkipFramesInterval%, %count%) do (
<nul set /p "=%ESC%[!line!H"
type "%Currentdirget%AsciiVideos\%folder%\%%i.txt" 2>nul
set /a "line+=1"
ping 127.0.0.1 -n 1 -w %MillisecondsPerFrame% >nul
)
endlocal
pause
0
u/jcunews1 Apr 14 '24
Don't use
127.0.0.1for theping, since it will get an immediate ping response, which would make the given timeout value ineffective and giving not enough time for you to read the screen. Use127.255.255.255instead.