[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

File Last Modified Date

Posted on 2011-05-04
8
Medium Priority
?
370 Views
Last Modified: 2012-06-22
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
Comment
  • 3
  • 3
  • 2
8 Comments
 
LVL 60

Expert Comment

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

by:Chris Dent
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

Open in new window

Chris
0
 

Author Comment

by:bnorrisatnortechsolutions
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
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

 

Author Comment

by:bnorrisatnortechsolutions
ID: 35692173
Well the file name and the date.  Sorry!!
0
 
LVL 71

Expert Comment

by:Chris Dent
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

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

Open in new window

~bp
0
 

Author Comment

by:bnorrisatnortechsolutions
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

by:
Bill Prew earned 1600 total points
ID: 35693485
Sure, how about this.

@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%"

Open in new window

~bp
0

Featured Post

SMB Security Just Got a Layer Stronger

WatchGuard acquires Percipient Networks to extend protection to the DNS layer, further increasing the value of Total Security Suite.  Learn more about what this means for you and how you can improve your security with WatchGuard today!

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

591 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