xml - Batch scripting return most recent folder name with string match in text file -


i created little batch script looks through folders sequential name given root folder , returns latest created:

@echo off /f "delims=" %%i in ('dir c:\rootfolder\foldername_* /b /ad-h /t:c /o-d') ( set a=%%i goto :found ) echo no folder found goto :eof :found echo recent directory: %a% 

now have enhance returning recent directory contains following string

name="test" value="completed" 

within file called test.xml in subfolder called test.

f.e. have

  1. c:\rootfolder\foldername_1\ --- created today --- test\test.xml not containing string
  2. c:\rootfolder\foldername_2\ --- created yesterday --- not finding test\test.xml
  3. c:\rootfolder\foldername_3\ --- created 3 days ago test\test.xml , matching string within
  4. c:\rootfolder\foldername_4\ --- created 4 days ago test\test.xml , matching string within

then folder should returned number 3.

is there way achieve this?

thank in advance!

to latest created directory, pattern, using powershell:

get-childitem foldername_* | sort creationtimeutc 

extending little bit further, consider test.xml:

dir rootfolder_* |  sort creationtimeutc | select -property fullname, @{name="xmlfile";expression={ $_.fullname + "\test.xml"}} | { test-path $_.xmlfile } |  select fullname, @{name="xmlcontent";expression={ get-content ($_.xmlfile)}} | { $_.xmlcontent -match "value=""completed""" } | select -expandproperty fullname -first 1 

you tune little bit, newest xml file contains pattern:

dir rootfolder_*\test.xml |  { test-path $_.fullname } |  select fullname, @{name="xmlcontent";expression={ get-content ($_.fullname)}} | { $_.xmlcontent -match "value=""completed""" } | select -first 1 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -