Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Deleting a file, creating a new one...

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,59630
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Deleting a file, creating a new one...
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Deleting a file, creating a new one... - 4/30/2008 2:39:52 AM   
  Hercules

 

Posts: 5
Score: 0
Joined: 4/30/2008
Status: offline
I have had this problem today... I'm using the FileSystemObject to delete a file, and then create a new one.

The problem is, every time I delete the old one and recreate -- it keeps the modified date of the OLD file! How do I get around this?

Thanks!
 
 
Post #: 1
 
 RE: Deleting a file, creating a new one... - 4/30/2008 2:48:27 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Hmmm...that is odd. Could you post your code?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Hercules)
 
 
Post #: 2
 
 RE: Deleting a file, creating a new one... - 4/30/2008 2:53:50 AM   
  Hercules

 

Posts: 5
Score: 0
Joined: 4/30/2008
Status: offline

      

(in reply to Hercules)
 
 
Post #: 3
 
 RE: Deleting a file, creating a new one... - 4/30/2008 2:54:26 AM   
  Hercules

 

Posts: 5
Score: 0
Joined: 4/30/2008
Status: offline
I tried destroying the object and using a different one, as you can see.. jsut frustrated now! :)

(in reply to Hercules)
 
 
Post #: 4
 
 RE: Deleting a file, creating a new one... - 4/30/2008 3:05:24 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Unfortunately it doesn't happen for me. This code works fine:

Set fso = CreateObject("Scripting.FileSystemObject")
WScript.Echo "Before delete: " & fso.GetFile("C:\Test.txt").DateLastModified
fso.DeleteFile "c:\test.txt"
WScript.Sleep 3000
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set f = fso.OpenTextFile("c:\test.txt", ForWriting, True)
f.WriteLine date() & " " & time() & " - "
f.Close

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Hercules)
 
 
Post #: 5
 
 RE: Deleting a file, creating a new one... - 4/30/2008 3:07:18 AM   
  Hercules

 

Posts: 5
Score: 0
Joined: 4/30/2008
Status: offline
Try it a few times... it gets off after you wait for a few minutes :(

(in reply to ebgreen)
 
 
Post #: 6
 
 RE: Deleting a file, creating a new one... - 4/30/2008 3:16:07 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Just ran it again and it showed an 11 minutes difference (since i last ran it 11 minutes ago).

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Hercules)
 
 
Post #: 7
 
 RE: Deleting a file, creating a new one... - 4/30/2008 3:23:50 AM   
  Hercules

 

Posts: 5
Score: 0
Joined: 4/30/2008
Status: offline
See, I'm not crazy! :)

(in reply to ebgreen)
 
 
Post #: 8
 
 RE: Deleting a file, creating a new one... - 4/30/2008 3:28:07 AM   
  crsgardner

 

Posts: 3
Score: 0
Joined: 4/30/2008
Status: offline
I think he's referring to the creation date, and I'm having a similar problem.  I'm trying to write a script that'll recreate a file every time with a new creation date.  If you change the script slightly to show creation date you'll see what I mean (and what I think he means):

Set fso = CreateObject("Scripting.FileSystemObject")
WScript.Echo "Before delete: " & fso.GetFile("C:\test.txt").DateCreated
fso.DeleteFile "c:\test.txt"
WScript.Sleep 3000
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set f = fso.OpenTextFile("C:\test.txt", ForWriting, True)
f.WriteLine date() & " " & time() & " - "
f.Close

Oddly enough, it will always retain the DateCreated of the "old" file, even though it's completely deleted (try running the script a few times and you'll see the date never changes).  You can also verify by viewing the properties of the file in Explorer -- the creation date will never change even though the file is gone.  It's bizarre.

(in reply to ebgreen)
 
 
Post #: 9
 
 RE: Deleting a file, creating a new one... - 4/30/2008 3:45:58 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Aaah...yes you are correct that I see that behavior for DateCreated. Hmmm...odd I will look into this. I'm curious though why you need to rely on DateCreated instead of DateLastModified?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to crsgardner)
 
 
Post #: 10
 
 RE: Deleting a file, creating a new one... - 4/30/2008 4:10:21 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Ok, for what it's worth, deleting the file through the Explorer UI does cause the DateCreated date to be right the next time the script runs.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ebgreen)
 
 
Post #: 11
 
 RE: Deleting a file, creating a new one... - 4/30/2008 4:45:24 AM   
  crsgardner

 

Posts: 3
Score: 0
Joined: 4/30/2008
Status: offline
quote:

ORIGINAL: ebgreen

Ok, for what it's worth, deleting the file through the Explorer UI does cause the DateCreated date to be right the next time the script runs.


Yes, and if you separate out the delete and creation lines into their own scripts, it works.  There must be some kind of object reference being retained.

What we ended up doing was using a shell command (e.g. WshShell.Run ("cmd /c del C:\test.txt")), which is a workaround at best.

(in reply to ebgreen)
 
 
Post #: 12
 
 RE: Deleting a file, creating a new one... - 4/30/2008 4:58:14 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Well I'm glad you found a solution. I still question the need for tracking the DateCreated as opposed to DateLastModified.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to crsgardner)
 
 
Post #: 13
 
 RE: Deleting a file, creating a new one... - 4/30/2008 5:15:17 AM   
  crsgardner

 

Posts: 3
Score: 0
Joined: 4/30/2008
Status: offline
The software we're interacting with requires a file with a new creation date to trigger processes.  It's not something we directly control.

(in reply to ebgreen)
 
 
Post #: 14
 
 RE: Deleting a file, creating a new one... - 4/30/2008 5:36:37 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Ehh..I see the delimma then.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to crsgardner)
 
 
Post #: 15
 
 RE: Deleting a file, creating a new one... - 4/30/2008 7:49:57 AM   
  Rischip


Posts: 414
Score: 2
Joined: 3/26/2007
Status: offline
On my system it appears that the actual delete on the physical drive and the create require a 20 second delay for the cache to clear out.
That's 20 seconds between operations before the cache clears or else the new file will contain the old create date.

_____________________________

Rischip
Author of - The Grim Linker

(in reply to ebgreen)
 
 
Post #: 16
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Deleting a file, creating a new one... Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts