Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Buffering the output of a "dir" command

03 Jun 2015   #1
swiftie

Windows 7 Ultimate x64
 
 
Buffering the output of a "dir" command

I had a command prompt open in a directory that contained 8 files. I wanted to keep an inventory of the 8 files, so I ran the command:

C:\>dir > inventory.2015-06-03

When I looked at the contents of inventory.2015-06-03 I was surprised to find that it contained the inventory.2015-06-03 file itself, as a 0 byte file.

Is there a technique to buffer the output from the "dir" command before the ">" takes effect, so I don't get the extra file in my listing?


My System SpecsSystem Spec
.
03 Jun 2015   #2
GokAy

Windows 7 Ultimate x64 SP1
 
 

You can try:
dir | findstr /v /i "\myfile.txt$" > myfile.txt

in case symbols don't make it
Buffering the output of a "dir" command-dir-exclude-file-write-txt.jpg


My System SpecsSystem Spec
03 Jun 2015   #3
swiftie

Windows 7 Ultimate x64
 
 

Thanks - your example works perfectly (of course).

It's interesting to find the use of Regular Expressions in a Windows context. For a moment I thought I'd strayed into a Linux discussion.
My System SpecsSystem Spec
.

03 Jun 2015   #4
GokAy

Windows 7 Ultimate x64 SP1
 
 

I don't know much about switches and whatnot, searched google with: cmd dir exclude files

this came up:
Excluding files of particular extension using DIR command on windows command line - Super User

then added your "> text.file" part to it, tried in my PC, posted for you
My System SpecsSystem Spec
03 Jun 2015   #5
Ztruker

Windows 10 Pro X64
 
 

No regular expression there: dir | findstr /v /i "\myfile.txt$" > myfile.txt

In english this says:

Display the list of files and folders in the current directory.
Pipe the output to the find string command. Make it case insensitive and exclude the file myfile.txt$ ($ meaning anything)
then redirect the output to myfile.txt.
My System SpecsSystem Spec
04 Jun 2015   #6
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

Quote   Quote: Originally Posted by Ztruker View Post
No regular expression there: dir | findstr /v /i "\myfile.txt$" > myfile.txt
The text in red is a regular expression. At least it's supposed to be.

GokAy, your regex, \myfile.txt$, is slightly incorrect.


Recalling a few special character meanings in regular expressions:
  • "\" is an escape character,
  • "." represents any single character,
  • "$" at the end of a regex means that the string to match should only be matched at the end of a line (immediately before any line break).
So the regex \myfile.txt$ actually says to match the string literal myfile, any character, and the string literal txt. $ at the end of a regex says that the string to match must be at the end of a line, before a line break character. Escaping the literal character m doesn't do anything.

This particular regular expression can be expressed in wildcard notation too. Its wildcard notation would be myfile?txt (where ? in wildcard notation represents any single character). This, however, will not say to match at the end of a line.

The correct regular expression that should be used in the Findstr command should be myfile\.txt$.


I presume you've already realised this by now, but there is no way to extend the output buffer of commands, Swiftie. GokAy's solution of filtering the output of Dir is exactly how your problem should be tackled.
My System SpecsSystem Spec
08 Jun 2015   #7
swiftie

Windows 7 Ultimate x64
 
 

Thanks to all for the help offered. It was the "$" in "\myfile.txt$" that showed me it was a regular expression. I hadn't noticed that the "\" and the "." were not quite right, but I no longer use regular expressions much since I retired (from IBM)
My System SpecsSystem Spec
Reply

 Buffering the output of a "dir" command




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
"Copy" command in command prompt generates 0x1a artifact?
Hello Everybody! I don't know if this is a real issue, or just one of those "What the . . . .!!" situations. You judge. Situation: I was working on a batch file that combines two .txt (ASCII?) files created in Notepad to create a composite file, and I noticed something really interesting. ...
Software
Command Prompt Error: "Cannot find directory "C:\Users\..."
Hello, I have basic knowledge of the command terminal, in that I only know how to navigate through directories. Currently I am trying to execute the following: java jar MRTBatch.jar d input_directory p parameter_directory\input_parameter_file o parameter_file_directory I have...
General Discussion
Run "cmd.exe" as a given user and "as administrator" in command line
Hello and thank you for reading my post. If I'm logged in Windows as user "u1", I can execute "cmd.exe" "as administrator" by choosing "Start" -> "cmd.exe" and right-click "Run as administrator".I would like to start another "cmd.exe" console as "u2" and "as administrator". (So, "u2" is not...
General Discussion
need "always on top icon & msg for "default audio input/output device"
I need to always display the default audio input and audio output device currently on win7. Would like to launch a small program on change as well or instead. I tried to use task scheduler but was not able. Help! Thanks, Ray
Sound & Audio
No REG Command in "Open elevated command window here" DOS Box
I have used the @="cmd.exe /s /k pushd \"%V\"" type of Registry mod to obtain a context menu "Open elevated command window here" menu item, such as in the "Open elevated command window here" thread ( http://www.sevenforums.com/general-discussion/75069-open-elevated-command-window-here.html ). ...
General Discussion
I have a HDMi "output" can I use as "input" to capture?
I want to capture like something that uses HDMi e.g. Xbox330 Or my from new ROgers HDPVR. I wanted teh highest quality Can I capture through the hdmi port I use for outputting HDMI Or what would I have to use to capture from my HDPVR HP dv7-2078ca PC Specifications ...
Graphic Cards


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 09:00.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App