Solved

Posted on 2011-05-04
369 Views
Can someone assist me with creating a script that checks for the file last modified date?  I want to be able to place a couple file paths in a txt file and have a script check the files listed in the txt file for their last modified date.
0

LVL 51

Expert Comment

Do you just want to display that date, or do you want to perform some logic based on it?

~bp
0

LVL 70

Assisted Solution

If it's just reporting, the PS version is this:
Get-Content YourList.txt | ForEach-Object { Get-Item \$_ } | Select-Object Name, FullName, LastWriteTime

Chris
0

Author Comment

All I need is the date.  I will then consume that into a SQL table, but for now all I want is the date to be displayed.
0

Author Comment

Well the file name and the date.  Sorry!!
0

LVL 70

Expert Comment

Do you really want PS for this? Trimming out the FullName property from my Select-Object statement above will leave you with name and date.

No idea how to do that in batch, but I'm certain bp does, he's very good at batch :)

Chris
0

LVL 51

Expert Comment

Okay, here's a small BAT file that will do the job.  You can specify the name of the list of files to process on the command line like:

EE27018150.bat EE27018150.txt

or if no filename is provided on the command line the script will prompt for it.

@echo off

REM File containing list of files to report on can be on the command line,
REM or will be prompted for
if "%~1"=="" (
set /p "FileList=Please specify name of file list file: "
) else (
set FileList=%~1
)
if not exist "%FileList%" (
echo ERROR: File [%FileList%] does not exist.
exit /b
)

REM For each file listing in the file report last modified date/time
for /F "usebackq tokens=*" %%A in ("%FileList%") do (
if exist "%%~A" (
echo "%%~A",%%~tA
) else (
echo "%%~A",N/A
)
)

~bp
0

Author Comment

Can we pipe the results to a .txt file?  Also can we hard code the list of files file into the batch file?  I am using C:\FileList.txt for S&Gs.
0

LVL 51

Accepted Solution

@echo off

REM Specify output CSV file location
set Output=x:\ee\EE27018150\EE27018150.csv

REM Specify files to process
set Files="x:\ee\test1_4.pdf","x:\ee\test2 4.pdf"

REM For each file listing in the file report last modified date/time
(for %%A in (%Files%) do (if exist "%%~A" (echo "%%~A",%%~tA) else (echo "%%~A",N/A)))>"%Output%"

~bp
0

## Featured Post

A commonly asked question on the site recently has been regarding how do I share the GAL between different forests? I want a list of Contacts representing all the users in a remote domain, How do i get them? It's a problem I was posed with a litt…
Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
how to add IIS SMTP to handle application/Scanner relays into office 365.
This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.