how to write date modified into text file ? 
Author Message
 how to write date modified into text file ?

I have a file on a share \\server\share\file.exe

I would like to create a script which will look at the modification date of
this file, and then output the modification date into a text file on the
user's hard drive, c:\log.txt

The script should constantly compare the modification date of
\\server\share\file.exe with the date inserted into the log.txt file, and if
the server's file modification date becomes more recent, then the script
should update the log file on the user's hard drive with the new
modification date.

Does my request make sense and if so, can someone show me how?



Tue, 05 Oct 2004 00:05:30 GMT  
 how to write date modified into text file ?
Since you're not doing anything if the date is different, why not just write
the date to the file each time the script is ran. If you do want to do
something, such as pop up a message, let me know and I'll show you how to do
the compare.

---Cut Here--------------------------------------------------------
  Option Explicit
  Dim oFS

  Set oFS = WScript.CreateObject("Scripting.FileSystemObject")

    Const sFile = "\\server\share\file.exe"
    Const  sLog = "C:\Log.Txt"

    LogDate sFile, sLog

    oWS.Run "notepad.exe " & sLog

  Set oFS = Nothing
  WScript.Quit

'---------------------
  Sub LogDate(sFile, sLog)
    Dim oLog
    Set oLog = oFS.OpenTextFile(sLog,2,True)
      oLog.WriteLine GetModDate(sFile)
      oLog.Close
    Set oLog = Nothing
  End Sub

'---------------------
  Function GetModDate(sFile)
    GetModDate = oFS.GetFile(sFile).DateLastModified
  End Function

---Cut Here--------------------------------------------------------

Quote:
> I have a file on a share \\server\share\file.exe

> I would like to create a script which will look at the modification date
of
> this file, and then output the modification date into a text file on the
> user's hard drive, c:\log.txt



Tue, 05 Oct 2004 06:03:13 GMT  
 how to write date modified into text file ?

Quote:
> I have a file on a share \\server\share\file.exe

> I would like to create a script which will look at the modification
> date of this file, and then output the modification date into a text
> file on the user's hard drive, c:\log.txt

> The script should constantly compare the modification date of
> \\server\share\file.exe with the date inserted into the log.txt file,
> and if the server's file modification date becomes more recent, then
> the script should update the log file on the user's hard drive with
> the new modification date.

> Does my request make sense and if so, can someone show me how?

This example script runs forever and checks the file's last modified date every 15 seconds and appends any changes to a log file...

set fso = createobject("scripting.filesystemobject")
sLog = "c:\mylog.txt"
sFile = "\\server\share\file.exe"
dtPrev = now()
do
  dtFile = fso.getfile(sFile).datelastmodified
  if datedif("s",dtPrev,dtFile) <> 0 then
    dtPrev = dtFile
    fso.opentextfile(sLog,8,true).writeline dtFile
  end if
  wscript.sleep 15 * 1000
loop while true '***this is an infinite loop***

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Tue, 05 Oct 2004 08:49:23 GMT  
 how to write date modified into text file ?
Thanks Michael,

The thing is, I don't want the script to append the date to end of the log
file such that the log file keeps a history of all these dates...  I just
want the log file to have one line in it, that being the date-modified of
the file we are checking on the server.  If the server's file changes, then
I want the script to update the log file with the new date-modified of this
file.



Quote:
> I have a file on a share \\server\share\file.exe

> I would like to create a script which will look at the modification
> date of this file, and then output the modification date into a text
> file on the user's hard drive, c:\log.txt

> The script should constantly compare the modification date of
> \\server\share\file.exe with the date inserted into the log.txt file,
> and if the server's file modification date becomes more recent, then
> the script should update the log file on the user's hard drive with
> the new modification date.

> Does my request make sense and if so, can someone show me how?

This example script runs forever and checks the file's last modified date
every 15 seconds and appends any changes to a log file...

set fso = createobject("scripting.filesystemobject")
sLog = "c:\mylog.txt"
sFile = "\\server\share\file.exe"
dtPrev = now()
do
  dtFile = fso.getfile(sFile).datelastmodified
  if datedif("s",dtPrev,dtFile) <> 0 then
    dtPrev = dtFile
    fso.opentextfile(sLog,8,true).writeline dtFile
  end if
  wscript.sleep 15 * 1000
loop while true '***this is an infinite loop***

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Tue, 05 Oct 2004 21:43:39 GMT  
 how to write date modified into text file ?
Then change

 fso.opentextfile(sLog,8,true).writeline dtFile

to

 fso.opentextfile(sLog,2,true).writeline dtFile

The parameters are in the docs.

Quote:

> Thanks Michael,

> The thing is, I don't want the script to append the date to end of the log
> file such that the log file keeps a history of all these dates...  I just
> want the log file to have one line in it, that being the date-modified of
> the file we are checking on the server.  If the server's file changes, then
> I want the script to update the log file with the new date-modified of this
> file.



> > I have a file on a share \\server\share\file.exe

> > I would like to create a script which will look at the modification
> > date of this file, and then output the modification date into a text
> > file on the user's hard drive, c:\log.txt

> > The script should constantly compare the modification date of
> > \\server\share\file.exe with the date inserted into the log.txt file,
> > and if the server's file modification date becomes more recent, then
> > the script should update the log file on the user's hard drive with
> > the new modification date.

> > Does my request make sense and if so, can someone show me how?

> This example script runs forever and checks the file's last modified date
> every 15 seconds and appends any changes to a log file...

> set fso = createobject("scripting.filesystemobject")
> sLog = "c:\mylog.txt"
> sFile = "\\server\share\file.exe"
> dtPrev = now()
> do
>   dtFile = fso.getfile(sFile).datelastmodified
>   if datedif("s",dtPrev,dtFile) <> 0 then
>     dtPrev = dtFile
>     fso.opentextfile(sLog,8,true).writeline dtFile
>   end if
>   wscript.sleep 15 * 1000
> loop while true '***this is an infinite loop***

> --
> Michael Harris
> Microsoft.MVP.Scripting
> Seattle WA US
> --



Tue, 05 Oct 2004 22:13:10 GMT  
 how to write date modified into text file ?
doesn't the script that michael posted check to see if the date-modified of
\\server\share\file.exe has changed in comparison to the last time the
script ran?  As opposed to what I need, which is this:

The file "c:\mylog.txt"  has one entry in it:  04/18/2002 8:01:01 AM

The script will check this entry and compare it to the date modified of
\\server\share\file.exe

If the date-modified of \\server\share\file.exe is more recent than the
entry in c:\mylog.txt, then overwrite the entry in c:\mylog.txt with the
date-modified of \\server\share\file.exe

--------------



Quote:
> Then change

>  fso.opentextfile(sLog,8,true).writeline dtFile

> to

>  fso.opentextfile(sLog,2,true).writeline dtFile

> The parameters are in the docs.




Quote:
> > Thanks Michael,

> > The thing is, I don't want the script to append the date to end of the
log
> > file such that the log file keeps a history of all these dates...  I
just
> > want the log file to have one line in it, that being the date-modified
of
> > the file we are checking on the server.  If the server's file changes,
then
> > I want the script to update the log file with the new date-modified of
this
> > file.



> > > I have a file on a share \\server\share\file.exe

> > > I would like to create a script which will look at the modification
> > > date of this file, and then output the modification date into a text
> > > file on the user's hard drive, c:\log.txt

> > > The script should constantly compare the modification date of
> > > \\server\share\file.exe with the date inserted into the log.txt file,
> > > and if the server's file modification date becomes more recent, then
> > > the script should update the log file on the user's hard drive with
> > > the new modification date.

> > > Does my request make sense and if so, can someone show me how?

> > This example script runs forever and checks the file's last modified
date
> > every 15 seconds and appends any changes to a log file...

> > set fso = createobject("scripting.filesystemobject")
> > sLog = "c:\mylog.txt"
> > sFile = "\\server\share\file.exe"
> > dtPrev = now()
> > do
> >   dtFile = fso.getfile(sFile).datelastmodified
> >   if datedif("s",dtPrev,dtFile) <> 0 then
> >     dtPrev = dtFile
> >     fso.opentextfile(sLog,8,true).writeline dtFile
> >   end if
> >   wscript.sleep 15 * 1000
> > loop while true '***this is an infinite loop***

> > --
> > Michael Harris
> > Microsoft.MVP.Scripting
> > Seattle WA US
> > --



Tue, 05 Oct 2004 22:38:26 GMT  
 how to write date modified into text file ?
set fso = createobject("scripting.filesystemobject")
sLog = "c:\mylog.txt"
sFile = "\\server\share\file.exe"
dtPrev = now()
if fso.fileexists(sLog) then
  if fso.getfile(sLog).size > 0 then
    sDate = fso.opentextfile(sLog,1).readline
    if isdate(sDate) then
      dtPrev = cdate(sDate)
    end if
  end if
end if
do
  dtFile = fso.getfile(sFile).datelastmodified
  if datediff("s",dtPrev,dtFile) <> 0 then
    dtPrev = dtFile
    fso.opentextfile(sLog,2,true).writeline dtFile
  end if
  wscript.sleep 15 * 1000
loop while true '***this is an infinite loop***

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Wed, 06 Oct 2004 01:52:40 GMT  
 how to write date modified into text file ?


Fri, 19 Jun 1992 00:00:00 GMT  
 how to write date modified into text file ?
That is perfect.

One question:  is it possible to create the "c:\mylog.txt" file as a hidden
file?



set fso = createobject("scripting.filesystemobject")
sLog = "c:\mylog.txt"
sFile = "\\server\share\file.exe"
dtPrev = now()
if fso.fileexists(sLog) then
  if fso.getfile(sLog).size > 0 then
    sDate = fso.opentextfile(sLog,1).readline
    if isdate(sDate) then
      dtPrev = cdate(sDate)
    end if
  end if
end if
do
  dtFile = fso.getfile(sFile).datelastmodified
  if datediff("s",dtPrev,dtFile) <> 0 then
    dtPrev = dtFile
    fso.opentextfile(sLog,2,true).writeline dtFile
  end if
  wscript.sleep 15 * 1000
loop while true '***this is an infinite loop***

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Wed, 06 Oct 2004 03:08:50 GMT  
 how to write date modified into text file ?

Quote:
> One question:  is it possible to create the "c:\mylog.txt" file as a hidden
> file?

This is your last 'freebie' ;-)...

WSH 5.6 documentation download
http://msdn.microsoft.com/downloads/sample.asp?url=/MSDN-FILES/027/00...

set fso = createobject("scripting.filesystemobject")
sLog = "c:\mylog.txt"
sFile = "\\server\share\file.exe"
dtPrev = now()
if fso.fileexists(sLog) then
  attribs = fso.getfile(sLog).attributes Or 2 'hidden
  fso.getfile(sLog).attributes = attribs
  if fso.getfile(sLog).size > 0 then
    sDate = fso.opentextfile(sLog,1).readline
    if isdate(sDate) then
      dtPrev = cdate(sDate)
    end if
  end if
else
  fso.createtextfile sLog
  attribs = fso.getfile(sLog).attributes Or 2 'hidden
  fso.getfile(sLog).attributes = attribs
end if
do
  dtFile = fso.getfile(sFile).datelastmodified
  if datediff("s",dtPrev,dtFile) <> 0 then
    dtPrev = dtFile
    fso.opentextfile(sLog,2,true).writeline dtFile
  end if
  wscript.sleep 15 * 1000
loop while true '***this is an infinite loop***

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Wed, 06 Oct 2004 03:30:41 GMT  
 how to write date modified into text file ?
The script creates the "c:\mylog.txt" file but errors with a "permission
denied" when it tries to write to the file, so the file ends up empty..



Quote:
> One question:  is it possible to create the "c:\mylog.txt" file as a
hidden
> file?

This is your last 'freebie' ;-)...

WSH 5.6 documentation download
http://msdn.microsoft.com/downloads/sample.asp?url=/MSDN-FILES/027/00...
sdncompositedoc.xml

set fso = createobject("scripting.filesystemobject")
sLog = "c:\mylog.txt"
sFile = "\\server\share\file.exe"
dtPrev = now()
if fso.fileexists(sLog) then
  attribs = fso.getfile(sLog).attributes Or 2 'hidden
  fso.getfile(sLog).attributes = attribs
  if fso.getfile(sLog).size > 0 then
    sDate = fso.opentextfile(sLog,1).readline
    if isdate(sDate) then
      dtPrev = cdate(sDate)
    end if
  end if
else
  fso.createtextfile sLog
  attribs = fso.getfile(sLog).attributes Or 2 'hidden
  fso.getfile(sLog).attributes = attribs
end if
do
  dtFile = fso.getfile(sFile).datelastmodified
  if datediff("s",dtPrev,dtFile) <> 0 then
    dtPrev = dtFile
    fso.opentextfile(sLog,2,true).writeline dtFile
  end if
  wscript.sleep 15 * 1000
loop while true '***this is an infinite loop***

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Wed, 06 Oct 2004 03:50:37 GMT  
 how to write date modified into text file ?
but it does successfully create it as hidden..



Quote:
> One question:  is it possible to create the "c:\mylog.txt" file as a
hidden
> file?

This is your last 'freebie' ;-)...

WSH 5.6 documentation download
http://msdn.microsoft.com/downloads/sample.asp?url=/MSDN-FILES/027/00...
sdncompositedoc.xml

set fso = createobject("scripting.filesystemobject")
sLog = "c:\mylog.txt"
sFile = "\\server\share\file.exe"
dtPrev = now()
if fso.fileexists(sLog) then
  attribs = fso.getfile(sLog).attributes Or 2 'hidden
  fso.getfile(sLog).attributes = attribs
  if fso.getfile(sLog).size > 0 then
    sDate = fso.opentextfile(sLog,1).readline
    if isdate(sDate) then
      dtPrev = cdate(sDate)
    end if
  end if
else
  fso.createtextfile sLog
  attribs = fso.getfile(sLog).attributes Or 2 'hidden
  fso.getfile(sLog).attributes = attribs
end if
do
  dtFile = fso.getfile(sFile).datelastmodified
  if datediff("s",dtPrev,dtFile) <> 0 then
    dtPrev = dtFile
    fso.opentextfile(sLog,2,true).writeline dtFile
  end if
  wscript.sleep 15 * 1000
loop while true '***this is an infinite loop***

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Wed, 06 Oct 2004 04:16:49 GMT  
 how to write date modified into text file ?

Quote:

> The script creates the "c:\mylog.txt" file but errors with a "permission
> denied" when it tries to write to the file, so the file ends up empty..

Well, it works perfectly for me exactly as written and posted (except for giving sFile the name of a real file)...

Are you testing with my example or something you wrote using the example?  If the latter is the case, then you'll have to post exactly the code you are using...

If you have sufficient NT permissions to create the log file and then set the hidden attribute then you clearly have enough NT sufficient permissions to write to the file.  The only reason you might not is if another process has it locked and/or opened for update precisely when *you* want to open/write to it...

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Wed, 06 Oct 2004 04:47:14 GMT  
 how to write date modified into text file ?
okay fair enough, thanks for help Michael.



Quote:

> The script creates the "c:\mylog.txt" file but errors with a "permission
> denied" when it tries to write to the file, so the file ends up empty..

Well, it works perfectly for me exactly as written and posted (except for
giving sFile the name of a real file)...

Are you testing with my example or something you wrote using the example?
If the latter is the case, then you'll have to post exactly the code you are
using...

If you have sufficient NT permissions to create the log file and then set
the hidden attribute then you clearly have enough NT sufficient permissions
to write to the file.  The only reason you might not is if another process
has it locked and/or opened for update precisely when *you* want to
open/write to it...

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Wed, 06 Oct 2004 09:18:47 GMT  
 
 [ 14 post ] 

 Relevant Pages 

1. data's modified date as update's date

2. File modified date with vbscript

3. Change File Modified Date

4. Get Modified date of a file

5. Need to display last modified date for files in web page

6. script to update a file's last modified date

7. script to update a file's last modified date

8. Modifying a text file.

9. How to modify a text file

10. write date read date ...

11. Writing a text file

12. Writing to a text file

 

 
Powered by phpBB® Forum Software