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

Posted on 2014-07-14
Last Modified: 2014-07-15

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

Question by:luketr
    LVL 82

    Assisted Solution

    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.
    LVL 82

    Accepted Solution

    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

    LVL 51

    Expert Comment

    by:Bill Prew
    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:


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
    Set OWA language and time zone in Exchange for individuals, all users or per database.
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    6 Experts available now in Live!

    Get 1:1 Help Now