Using ‘echo’ in a way that automatically fits the row width

  batch-file, cmd, command-prompt, echo, windows

I have a need to display a list of files with full paths as just something to look at while processing. I don’t like how some results are so long they continue all the way to a second line, displeasing the aesthetic. I have a way to trim the rest of the file to fit my current window:

if "%echo%"=="%echo:~,160%" (echo %echo%) else (echo %echo:~,160%...)

This will successfully trim the line, and display ‘…’ in the end of a trimmed line to signal that the filename is cut off like so:

"d:this isa longpath toa file somewhere in the tree (21-08-22) ke…"

This method has the downside of only working on a certain size window. My question is how do I make this automatic? Is there a way to detect the characters per row automatically so each line is cut the right way for everyone, for every size window?

Source: Windows Questions

LEAVE A COMMENT