[Webinar] Streamline your web hosting managementRegister Today

x
Solved

Posted on 2011-05-04
Medium Priority
370 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
• 3
• 3
• 2

LVL 60

Expert Comment

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

~bp
0

LVL 71

Assisted Solution

Chris Dent earned 400 total points
ID: 35692165
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

ID: 35692167
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

ID: 35692173
Well the file name and the date.  Sorry!!
0

LVL 71

Expert Comment

ID: 35692306
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 60

Expert Comment

ID: 35693013
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

ID: 35693209
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 60

Accepted Solution

Bill Prew earned 1600 total points
ID: 35693485

@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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Transferring FSMO roles is done when an admin wants to split roles between certain Domain Controllers or the Domain Controller holding the Roles has been forcefully demoted using dcpromo / forceremoval
Loops Section Overview
Screencast - Getting to Know the Pipeline
###### Suggested Courses
Course of the Month9 days, 19 hours left to enroll