[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

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

Script to output result into text file on files in a directory


I need a script, it could be powershell or a batch script to look into a directory that contains sub folders with files. I need it to export any .doc or .docx that was created on or after 25/10/2013 to a text file with the full location path or each file.

Many thanks

  • 2
2 Solutions
Powershell (could easily be turned into a one-liner):
$Directory = "C:\Temp"
$Include = "*.doc", "*.docx"
$FilterDate = Get-Date "25/10/2013"
$ResultFile = "C:\Temp\Results.txt"
Get-Childitem $Directory -Recurse -Include $Include | Where {$_.LastWriteTime -ge $FilterDate} | Select-Object -ExpandProperty FullName | Out-File $ResultFile

Open in new window

Edit: Forgot the output to a file.
For the fun of it, here's a version that uses robocopy.exe (it doesn't actually copy anything, so the target folder doesn't matter) and can handle file paths over 250 characters; works both in cmd and PS. Make sure you provide the date in question as YYYYMMDD:
robocopy.exe "C:\Temp" "C:\DUMMY" *.doc *.docx /maxage:20131025 /e /l /np /fp /ndl /nc /ns /njh /njs >C:\Temp\test.txt

Open in new window

Bill PrewCommented:
I know the question is closed, glad you got help, and I know you asked for a script, but I did want to mention a small free utility I have used for things like this that can save scripting.  It's called Swiss File Knife (SFK) and can make things like this pretty easy once you get the hang of it.  For example, here's a one line command that does what you needed:

sfk list c:\temp *.doc *.docx -since 20131025>c:\temp\list.txt

Open in new window

You can find the utility here:



Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

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