• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1566
  • Last Modified:

findstr dos command need to exclude bytes free

From a win32 dos command box we can execute the dir command that shows the total free bytes on disk in the last line:

.....--output omitted--....
 Directory of C:\temp

21/10/2008  12:53    <DIR>          .
21/10/2008  12:53    <DIR>          ..
21/10/2008  12:53                 0 free.txt
               1 File(s)              0 bytes
               2 Dir(s)  142.985.986.048 bytes free

With the findstr command you can exclude string data from a command. I was trying to get the free bytes value from the last line 142.985.986.048 so i can put it in a variable.

Anyone that can help me a bit?

C:\>findstr /R "<<regular expression needed here>" |dir

more info on the findstr win32 command:
  • 4
  • 2
1 Solution
for /f "usebackq tokens=2,3,4" %i in (`dir`) do @if %k==bytes echo %j
> .. so i can put it in a variable.
for /f "usebackq tokens=2,3,4" %i in (`dir`) do @if %k==bytes set variable=%j
techneitsolutionsAuthor Commented:
"k was unexcpected at this time"

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

then your dir command returns strange results, it works for the xample given in the initial question
techneitsolutionsAuthor Commented:
Well i created two batch files:

example1.bat that holds the first post
example2.bat that holds the second post.

I executed both of them, see results in attached file...
> Well i created two batch ..
in batch files you have to double the %
read find help about stupid windoze syntax
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now