Situation:
I've got a vbscript that creates a logfile during processing. At the
beginning of the script I check to see if the log already exists - if
so, I rename it (move) then create a new log (CreateTextFile) for the
current execution.

Here's the code

1 Set objFSO = CreateObject("Scripting.FileSystemObject")
2 If objFSO.FileExists(myLogFile) Then
3 Set objFile = objFSO.GetFile(myLogFile)
4 objFile.Move(myLogFile & <a suffix containing the last modified
date>)
5 End If
6 Set objLogFile = objFSO.CreateTextFile(myLogFile, True)


The Problem:
The "DateCreated" attribute value seems be carried over from the
previous logfile (line 2) to the new logfile (line 6)... but the date
modified last accessed values are updated correctly. Why is the date
created value not getting the current date and how can I fix this
problem?

Any feedback on this would be appreciated...

celoftis

Re: Text File Create date problem... by Franz

Franz
Wed Nov 08 16:26:18 CST 2006

celoftis wrote:

> The Problem:
> The "DateCreated" attribute value seems be carried over from the
> previous logfile (line 2) to the new logfile (line 6)... but the date
> modified last accessed values are updated correctly. Why is the date
> created value not getting the current date and how can I fix this
> problem?

try by adding a

Set objLogFile = ""

between line 5 and 6





Re: Text File Create date problem... by celoftis

celoftis
Thu Nov 09 08:44:35 CST 2006

I didn't show this above but I already had:
Set objLogFile = Nothing

Regardless, trying to assign the object pointer a string value throws
an error:
Object required: "[string: ""]"


Franz aRTiglio wrote:
> celoftis wrote:
>
> > The Problem:
> > The "DateCreated" attribute value seems be carried over from the
> > previous logfile (line 2) to the new logfile (line 6)... but the date
> > modified last accessed values are updated correctly. Why is the date
> > created value not getting the current date and how can I fix this
> > problem?
>
> try by adding a
>
> Set objLogFile = ""
>
> between line 5 and 6


Re: Text File Create date problem... by Franz_aRTiglio

Franz_aRTiglio
Thu Nov 09 10:01:22 CST 2006

>I didn't show this above but I already had:
> Set objLogFile = Nothing
>
> Regardless, trying to assign the object pointer a string value throws
> an error:
> Object required: "[string: ""]"

how about adding a "fresh new" variable such as "oblLogFIleNew "

then passing from the old one all "old" values except the date ?



Re: Text File Create date problem... by celoftis

celoftis
Fri Nov 10 10:25:54 CST 2006

Franz_aRTiglio wrote:
> >I didn't show this above but I already had:
> > Set objLogFile = Nothing
> >
> > Regardless, trying to assign the object pointer a string value throws
> > an error:
> > Object required: "[string: ""]"
>
> how about adding a "fresh new" variable such as "oblLogFIleNew "
>
> then passing from the old one all "old" values except the date ?

I gave that a try to no avail - same result.
Any other ideas?


Re: Text File Create date problem... by ekkehard

ekkehard
Fri Nov 10 12:39:03 CST 2006

celoftis wrote:
> Situation:
> I've got a vbscript that creates a logfile during processing. At the
> beginning of the script I check to see if the log already exists - if
> so, I rename it (move) then create a new log (CreateTextFile) for the
> current execution.
>
> Here's the code
>
> 1 Set objFSO = CreateObject("Scripting.FileSystemObject")
> 2 If objFSO.FileExists(myLogFile) Then
> 3 Set objFile = objFSO.GetFile(myLogFile)
> 4 objFile.Move(myLogFile & <a suffix containing the last modified
> date>)
> 5 End If
> 6 Set objLogFile = objFSO.CreateTextFile(myLogFile, True)
>
>
> The Problem:
> The "DateCreated" attribute value seems be carried over from the
> previous logfile (line 2) to the new logfile (line 6)... but the date
> modified last accessed values are updated correctly. Why is the date
> created value not getting the current date and how can I fix this
> problem?
>
> Any feedback on this would be appreciated...
>
> celoftis
>
Running this program:

Dim nWait : nWait = 10 ' 1000
Dim bNuke : bNuke = False ' True
Dim sFSpec : sFSpec = ".\filesdates3"
Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" )

WScript.Echo CStr( bNuke ), nWait

Dim dtNow, oTS, oFi

dtNow = Now()
Set oTS = oFS.CreateTextFile( sFSpec, True )
oTS.WriteLine dtNow
oTS.Close
WScript.Echo dtNow, sFSpec, "created."
WScript.Sleep nWait

If bNuke Then
Set oFS = Nothing
WScript.Sleep nWait
Set oFS = CreateObject( "Scripting.FileSystemObject" )
End If

dtNow = Now()
Set oFi = oFS.GetFile( sFSpec )
WScript.Echo dtNow, sFSpec, "creationdate", oFi.DateCreated
Set oTS = oFS.OpenTextFile( sFSpec )
WScript.Echo dtNow, sFSpec, "saved date ", oTS.ReadLine
oTS.Close
WScript.Sleep nWait

dtNow = Now()
oFS.DeleteFile sFSpec
WScript.Echo dtNow, sFSpec, "deleted."

I get output like:

Falsch 10
10.11.2006 19:33:17 .\filesdates3 created.
10.11.2006 19:33:17 .\filesdates3 creationdate 10.11.2006 19:33:17
10.11.2006 19:33:17 .\filesdates3 saved date 10.11.2006 19:33:17
10.11.2006 19:33:17 .\filesdates3 deleted.
...
Falsch 10
10.11.2006 19:33:23 .\filesdates3 created.
10.11.2006 19:33:23 .\filesdates3 creationdate 10.11.2006 19:33:17
10.11.2006 19:33:23 .\filesdates3 saved date 10.11.2006 19:33:23
10.11.2006 19:33:23 .\filesdates3 deleted.
...
Falsch 10
10.11.2006 19:33:32 .\filesdates3 created.
10.11.2006 19:33:32 .\filesdates3 creationdate 10.11.2006 19:33:17
10.11.2006 19:33:32 .\filesdates3 saved date 10.11.2006 19:33:32
10.11.2006 19:33:32 .\filesdates3 deleted.

My conclusion: Don't trust .DateCreated. Of course, you may try whether
longer delays and/or zapping oFS and/or XP instead of W2K and/or Voodoo
will get you more reliable results.

Re: Text File Create date problem... by Franz

Franz
Fri Nov 10 16:04:00 CST 2006


"celoftis" <celoftis@gmail.com> ha scritto nel messaggio news:1163175954.845321.34490@h54g2000cwb.googlegroups.com...
> Franz_aRTiglio wrote:
>> >I didn't show this above but I already had:
>> > Set objLogFile = Nothing
>> >
>> > Regardless, trying to assign the object pointer a string value throws
>> > an error:
>> > Object required: "[string: ""]"
>>
>> how about adding a "fresh new" variable such as "oblLogFIleNew "
>>
>> then passing from the old one all "old" values except the date ?
>
> I gave that a try to no avail - same result.
> Any other ideas?

I ran some test and the new file does NOT carry the "old"
date, the old file is correctly renamed and keeps the old
dates except for the "last modified".

As example, I got a try with a "aaa.txt" file in my root disk;
I've run your script and a new file "aaa.txtblahblah" has been
created; I've checked the dates, so "aaa.txt" file now reports
TODAY for modified and last time accessed, "aaa.txtblahblah"
reports the old date time for "last modified" but today
for "last accessed".

So what is the problem ? Maybe I just misunderstood your
question, but please, tell me what you're trying to do...
in a different way... something like:

I wish to rename a file then create a new file, but
the old file should keep old values for the date/time (details)
and the new file should be created with actual values
for date/time (details)

As I mentioned, maybe I got puzzeld, but if you plan to
keep OLD values when renaming a file for both "created"
and "last accessed", I bet is quite impossible with VBS
because those values are andled directly by the
file system, not by the VBS engine, afaik it requires
a direct access to the filesystem object trought api
calls and changing the file's attributes directly.







Re: Text File Create date problem... by dNagel

dNagel
Fri Nov 10 16:35:20 CST 2006

I, too, ran his script and experienced his issue... I'm at a loss...

I tried to copy and then deleted the old one. Then I created a new
file with that original file name thinking it would be a suitable
workaround... oddly enough, I got the same result, which seems
impossible... but that's what happened.

fwiw,

Microsoft Windows XP [Version 5.1.2600]
Windows XP Pro 2002 SP 2

D.



Franz aRTiglio wrote:
> "celoftis" <celoftis@gmail.com> ha scritto nel messaggio news:1163175954.845321.34490@h54g2000cwb.googlegroups.com...
>
>> Franz_aRTiglio wrote:
>>
>>>> I didn't show this above but I already had:
>>>> Set objLogFile = Nothing
>>>>
>>>> Regardless, trying to assign the object pointer a string value throws
>>>> an error:
>>>> Object required: "[string: ""]"
>>>>
>>> how about adding a "fresh new" variable such as "oblLogFIleNew "
>>>
>>> then passing from the old one all "old" values except the date ?
>>>
>> I gave that a try to no avail - same result.
>> Any other ideas?
>>
>
> I ran some test and the new file does NOT carry the "old"
> date, the old file is correctly renamed and keeps the old
> dates except for the "last modified".
>
> As example, I got a try with a "aaa.txt" file in my root disk;
> I've run your script and a new file "aaa.txtblahblah" has been
> created; I've checked the dates, so "aaa.txt" file now reports
> TODAY for modified and last time accessed, "aaa.txtblahblah"
> reports the old date time for "last modified" but today
> for "last accessed".
>
> So what is the problem ? Maybe I just misunderstood your
> question, but please, tell me what you're trying to do...
> in a different way... something like:
>
> I wish to rename a file then create a new file, but
> the old file should keep old values for the date/time (details)
> and the new file should be created with actual values
> for date/time (details)
>
> As I mentioned, maybe I got puzzeld, but if you plan to
> keep OLD values when renaming a file for both "created"
> and "last accessed", I bet is quite impossible with VBS
> because those values are andled directly by the
> file system, not by the VBS engine, afaik it requires
> a direct access to the filesystem object trought api
> calls and changing the file's attributes directly.
>
>
>
>
>
>
>

Re: Text File Create date problem... by Franz

Franz
Fri Nov 10 16:53:13 CST 2006

dNagel wrote:

> I, too, ran his script and experienced his issue... I'm at a loss...
> I tried to copy and then deleted the old one. Then I created a new
> file with that original file name thinking it would be a suitable
> workaround... oddly enough, I got the same result, which seems
> impossible... but that's what happened.

Can you paste here your test script ?




Re: Text File Create date problem... by dNagel

dNagel
Fri Nov 10 17:15:12 CST 2006

' VB Script Document
option explicit
Dim objFSO
Dim objFile
dim objLogFile
Dim myLogFile
myLogFile = "C:\log.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(myLogFile) Then
Set objFile = objFSO.GetFile(myLogFile)
objFile.copy(myLogFile & "3")
objFile.Delete
End If
Set objLogFile = objFSO.CreateTextFile(myLogFile, True)


D.


Franz aRTiglio wrote:
> dNagel wrote:
>
>
>> I, too, ran his script and experienced his issue... I'm at a loss...
>> I tried to copy and then deleted the old one. Then I created a new
>> file with that original file name thinking it would be a suitable
>> workaround... oddly enough, I got the same result, which seems
>> impossible... but that's what happened.
>>
>
> Can you paste here your test script ?
>
>
>
>

Re: Text File Create date problem... by dNagel

dNagel
Fri Nov 10 17:22:27 CST 2006

I had already run this script at 8:44 am and this is the result after
running again at 3:16p

showing creation date

C:\>dir /tC log*.*
11/10/2006 08:37 AM 0 log.txt
11/10/2006 08:37 AM 0 log.txt3

showing written date

C:\>dir /tW log*.*
11/10/2006 03:16 PM 0 log.txt
11/10/2006 08:44 AM 0 log.txt3

D.

Franz aRTiglio wrote:
> dNagel wrote:
>
>
>> I, too, ran his script and experienced his issue... I'm at a loss...
>> I tried to copy and then deleted the old one. Then I created a new
>> file with that original file name thinking it would be a suitable
>> workaround... oddly enough, I got the same result, which seems
>> impossible... but that's what happened.
>>
>
> Can you paste here your test script ?
>
>
>
>

Re: Text File Create date problem... by Franz

Franz
Fri Nov 10 17:47:03 CST 2006

dNagel wrote:

>I had already run this script at 8:44 am and this is the result after
> running again at 3:16p

I grabbed a ooooold log.txt from my HD then copyed it to the root

> showing creation date
> C:\>dir /tC log*.*
> 11/10/2006 08:37 AM 0 log.txt
> 11/10/2006 08:37 AM 0 log.txt3

11/11/2006 00.32 0 log.txt
11/11/2006 00.33 7.972 log.txt3

> showing written date
> C:\>dir /tW log*.*
> 11/10/2006 03:16 PM 0 log.txt
> 11/10/2006 08:44 AM 0 log.txt3

11/11/2006 00.33 0 log.txt
03/05/2004 14.58 7.972 log.txt3

On my PC, seems working correctly, even if I set the
system date to yesterday, then I create a log.txt file, then I turn
back the clock to today and re-run the script.

I always get the correct date/time....

That's odd... by the way, your filesystem is FAT32 or NTFS ? it's
just a guess.. I'm not sure it can be related to filesystem...

but hey... it's microsoft suff ... we can't expect it works logically :D
(just kidding)




Re: Text File Create date problem... by dNagel

dNagel
Fri Nov 10 18:25:32 CST 2006

NTFS.

D.

Franz aRTiglio wrote:
> dNagel wrote:
>
>
>> I had already run this script at 8:44 am and this is the result after
>> running again at 3:16p
>>
>
> I grabbed a ooooold log.txt from my HD then copyed it to the root
>
>
>> showing creation date
>> C:\>dir /tC log*.*
>> 11/10/2006 08:37 AM 0 log.txt
>> 11/10/2006 08:37 AM 0 log.txt3
>>
>
> 11/11/2006 00.32 0 log.txt
> 11/11/2006 00.33 7.972 log.txt3
>
>
>> showing written date
>> C:\>dir /tW log*.*
>> 11/10/2006 03:16 PM 0 log.txt
>> 11/10/2006 08:44 AM 0 log.txt3
>>
>
> 11/11/2006 00.33 0 log.txt
> 03/05/2004 14.58 7.972 log.txt3
>
> On my PC, seems working correctly, even if I set the
> system date to yesterday, then I create a log.txt file, then I turn
> back the clock to today and re-run the script.
>
> I always get the correct date/time....
>
> That's odd... by the way, your filesystem is FAT32 or NTFS ? it's
> just a guess.. I'm not sure it can be related to filesystem...
>
> but hey... it's microsoft suff ... we can't expect it works logically :D
> (just kidding)
>
>
>
>