Google Answers Logo
View Question
 
Q: File Date Conditional Batch Command ( Answered,   0 Comments )
Question  
Subject: File Date Conditional Batch Command
Category: Computers > Operating Systems
Asked by: schmerold-ga
List Price: $25.00
Posted: 29 Aug 2006 13:28 PDT
Expires: 28 Sep 2006 13:28 PDT
Question ID: 760568
I need a conditional batch command that will perform an action based
on a file's date.
for example:
set fl=c:\autoexec.bat
set dte=02-02-2002
if filedate(%fl%) LEQ %dte% echo %fl% is really old

I need the function to be built into Windows XP, available as freeware
or as a product that can be used on 50 computer for less than $100

Request for Question Clarification by theta-ga on 05 Sep 2006 09:46 PDT
Hi schmerold-ga,
    Is it necessary that you batch file be in the Windows Batch (.bat)
format? Microsoft has released a newer, more powerful scripting
environment known as Windows Scripting Host (.wsh) which has been a
part of all versions of Windows since 1998 (Windows 98, Windows Me,
Windows 2000, Windows Xp etc.). WSH files can be run just like the
.bat files, either from the command prompt or by simply clicking on
them. For more information, see:
http://www.winguides.com/article.php?id=2
    The file date comparison you require can be much easily done with
WSH than with the old .bat files. Will you be interested in a WSH
solution or is the use of .bat files a must?

Thanks,
Theta-ga
:)

Clarification of Question by schmerold-ga on 19 Sep 2006 01:29 PDT
wsh is fine, in your answer provide a solution that sets an
environment variable that can be used in the batch file.
for example the batch file may read:
wscript solution.wsh
if .%solution%==.1 copy \\fs1\share\test.exe c:\prog\test.exe
Answer  
Subject: Re: File Date Conditional Batch Command
Answered By: theta-ga on 21 Sep 2006 16:31 PDT
 
Hi schmerold-ga,
   In light of your needs, I decided that a WSH script would not be
the right solution. A WSH script would be the perfect solution if you
did not need to access its results from a Windows Batch file. Since
this was a requirement, I decided to implement a separate command-line
utility that you can call from a batch file. you can download this
utility from the following link:

    http://rapidshare.de/files/33977380/CompareFileDate.exe.html

To run the utility, use it at your command prompt or in your batch file, like this:
   CompareFileDate 20-11-2006 c:\autoexec.bat

The above command will compare the file creation date of
'c:\autoexec.bat' with the input date (20th Nov 2006) and store the
comparison result in the ERRORLEVEL environment variable. The result
can be -1,0 or 1 depending on whether the file creation date is less
than, equal to, or greater than the input date. In case of an error,
ERRORLEVEL is set to a value less than -1.
The utility also prints the file creation date of the specified file
onto the screen.

Given below is an example Windows batch file that makes use of this utility:
----------------------------------------------------------------
@echo off
CompareFileDate.exe 19-03-2005 c:\autoexec.bat

if ERRORLEVEL=0 (echo "equal" )else (echo "not equal")
 
----------------------------------------------------------------
Note that you must specify the full path to 'CompareFileDate.exe' if
the file is not in the same folder as the batch file.
Also note that the utility expects the input date to be in the format dd-mm-yyyy.

Hope this helps.
If you need any clarifications, just ask! i'll be glad to help.

Regards,
Theta-ga
:)
Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy