2

I have created a batch file which redirects into a plain text file. What the batch does is goes to the mentioned path and there dir command gets executed and the output will be directed to a text file.

Now when i open the text file i see the whole tree, but i want only one folder when i has been modified last.

So, can any one suggest what is the command that i have to give so that it picks only that folder and prints the same into my text file.

Below is the content of my batch file :

S:
cd S:\log\logit-esb\dhl\subscriptions
dir >> D:\Abhi_Work\System_Monitoring\System_monitoring.txt

When I run the batch file below is the output directed to my text file.

 Directory of S:\log\logit-esb\dhl\subscriptions

05/01/2015  04:25 PM    <DIR>          .
05/01/2015  04:25 PM    <DIR>          ..
05/01/2015  04:25 PM    <DIR>          processed
               0 File(s)              0 bytes
               3 Dir(s)   4,682,932,224 bytes free
 Volume in drive S is System
 Volume Serial Number is 42A7-D3B7

My requirement is i want only the below line to be displayed in the output file

05/01/2015  04:25 PM    <DIR>          processed

SO anyone help me in achieving this.

2
  • 1
    @paradroid piping to findstr is probably easier than using for /f ...
    – DavidPostill
    May 1, 2015 at 11:58
  • @DavidPostill Oh yeah, forgot about that.
    – paradroid
    May 1, 2015 at 12:09

2 Answers 2

2

The following command in your batch file will do what you want:

dir | findstr "processed" >> D:\Abhi_Work\System_Monitoring\System_monitoring.txt

You should first make sure System_monitoring.txt is an empty file as the >> will append to the file ...


Source Search for strings in files.

Piping and Redirection

A text file can be piped or redirected into FINDSTR:

Data stream from a pipe TYPE file.txt | FINDSTR "searchString"

Stdin via redirection FINDSTR "searchString"

The various data source specifications are mutually exclusive - FINDSTR can only work with one of the following: filename argument(s), /F:file option, redirected input, or piped input.

1
  • "i want only one folder when i has been modified last" - Looks like he wants to list only the last modified folder and not just a folder with a specific name.
    – Karan
    May 2, 2015 at 2:31
2

This is Powershell which is included in Windows 7 and will display the most recently modified folder in a path.

get-childitem -path c: | sort-object LastWriteTime -descending | select -first 1 | format-table -hidetableheaders

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .