Question Locked

Text Wrapping and Redirection in a DOS Window

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Now I know this is just a minor annoyance, but I was wondering if anyone had an explanation for the following behavior, or if possible, a solution.

My DOS window is 200 columns wide. The following command uses all 200 columns of the window:

C:\>dir /w

But when I pipe the output to any other program - more (yes, I know about /p. That's not the point.), find, findstr, etc. - or when I redirect the output to a file, text wrapping takes place at column 80.

If you're wondering why I'm asking, below is a batch file called ls.cmd, which aliases 'ls' to a big hairy DIR command. I wanted the output to be stripped of everything except the files and directories, so I piped DIR through FINDSTR to remove all the junk. But the last 120 empty columns of output just drive me nuts. Jed (in the cube beside me) says I need to 'just let it go,' but I'm sure you know how that goes. Any ideas?

File: ls.cmd
@echo off
dir /ogne/w "%~1" | findstr /v "^.Volume.in.drive. ^.Volume.Serial.Number. ^.Directory.of. ^.*[0-9,].*File(s).*[0-9,].bytes$ ^.*[0-9,].*Dir(s).*[0-9,].bytes.free$ ^$"

5 replies

by Member 25348569

I get a sorted list of folder names in [] followed by filenames. There doesn't seem to be anything missing. Except me and the point, maybe.

I'm using a Command Window on XPSP3 which is about 230 characters wide (to test).

by Member 27801784

I don't lose any content from the DIR command. The problem is that instead of wrapping the text at 200 characters, it is wrapped as if the window were only 80 columns wide. But this occurs only when I pipe or redirect the DIR output. (My example shows a pipe to FINDSTR.)

by Member 25348569

It's never going to work as you want because the Dir command doesn't pass lines of text - the woidth of the screen - to FINDSTR, it passes individual directory entries so FINDSTR deals with them one at a time and the output is in the form of single entries. One column is all you're going to get.

:)

This discussion is closed to new replies.