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

DOS Batch file: Script to display message based on file date

Using a DOS batch file (.bat) I am looking to display a message on the screen (or execute a program of my choosing) if a file, located on a network share, was modified earlier that today's date.

Here is what's going on:  
Every night, at midnight, a server outputs data to a text file in a network share; for example \\server\share\output.txt
Other users access this file to retrieve needed data
To ensure they get the data they need, I have to ensure the text file was created at, or after, midnight.
I do this by looking at the file's Modified Date.  If it's the same as today's date, I know it has current data.

In very loose programming syntax, I would like it to do this:
If \\server\share\output.txt = todays date
    do nothing
Else
    display "Error" on screen (or execute a program of my choosing)

Thank you.
0
dandickens
Asked:
dandickens
  • 4
  • 2
  • 2
1 Solution
 
Bill PrewCommented:
Can you tell me what the two commands below display if you execute them at a command prompt:

ECHO %DATE%

DIR \\SERVER\SHARE\OUTPUT.TXT

(where the last one is the actual file involved)

~bp
0
 
dandickensAuthor Commented:
ECHO %DATE%:
Wed 09/01/2010

DIR \\SERVER\SHARE\OUTPUT.TXT:
 Volume in drive \\SERVER\SHARE is New Volume
 Volume Serial Number is C840-B990

 Directory of \\SERVER|\SHARE

09/01/2010  12:07 AM        27,369,774 OUTPUT.txt
               1 File(s)     27,369,774 bytes
               0 Dir(s)  56,456,040,448 bytes free

0
 
Bill PrewCommented:
Okay, I think this BAT file should do the job.

~bp
@echo off
set CurrentDate=%DATE:~0,10%
for %%A in ("\\server\share\filename.txt") do for /F "tokens=1" %%B in ("%~tA") do set FileDate=%%B
if "%FileDate%" NEQ "%CurrentDate%" (
  echo File was not updated today!
  REM Run any program you desire here
)

Open in new window

0
Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

 
Bill PrewCommented:
Whoops, hold on, need to adjust that, to this.

~bp
@echo off
set CurrentDate=%DATE:~-10%
for %%A in ("\\server\share\filename.txt") do for /F "tokens=1" %%B in ("%~tA") do set FileDate=%%B
if "%FileDate%" NEQ "%CurrentDate%" (
  echo File was not updated today!
  REM Run any program you desire here
)

Open in new window

0
 
Steve KnightIT ConsultancyCommented:
You could also just do:
@echo off
dir \\server\share\yourfile.txt | find "%date:~-10%"  || (
  echo Is NOT todays date
) || (
  echo It is OK
)

i.e. use Find on the output of dir command of the relevant file and if it finds a match with the current date then run the bit after the &&

Steve
0
 
Steve KnightIT ConsultancyCommented:
Sorry Bill, hadn't refreshed there.  My second || should be && - I think I have that the right way around, i.e. if find does not find the date then it is an error and the || bit is run... been a long day and was only passing!
0
 
dandickensAuthor Commented:
Thanks to each of you for assisting me with this.   billprew:

running that batch produces this output -

The following usage of the path operator in batch-parameter
substitution is invalid: %~tA") do set FileDate=%%B

Any thoughts?
0
 
Bill PrewCommented:
Sorry, small typo there, change:

%~tA

to

%%~tA

~bp
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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