Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
314 views
in Technique[技术] by (71.8m points)

Powershell - merge .txt files into one - based on modified date

I have a folder with thousands of files

File1:

A B C

A B C

File 2:

1 2123

2345

ResultFile (output):

A B C

A B C



1 2123

2345

How can I merge those into one file - with some space between each file-content? I also want just those files modified today

This is what I have now

Get-ChildItem H:myFolder-include *.txt -rec | ForEach-Object {gc $_; ""} |  out-file H:est.txt

How can I add the date-condition in here?

question from:https://stackoverflow.com/questions/65936675/powershell-merge-txt-files-into-one-based-on-modified-date

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use the Where-Object cmdlet to filter data passed along the pipeline:

$startOfToday = (Get-Date).Date
Get-ChildItem H:myFolder-include *.txt -Recurse | Where-Object LastWriteTime -gt $startOfToday | ForEach-Object {$_ |gc ; ""} | Out-File H:est.txt

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...