Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Delete, Create, Code doesn't do what its supposed to.

Delete, Create, Code doesn't do what its supposed to.

Scheduled Pinned Locked Moved Visual Basic
helpquestionworkspace
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Karma31251
    wrote on last edited by
    #1

    Public Sub AppendTrackNumLog(ByVal LogText As String) Dim LogInfo As System.IO.FileInfo Dim createDate As DateTime LogInfo = My.Computer.FileSystem.GetFileInfo("t:\PowderedLogs\TrackNumLogPowdered.txt") createDate = LogInfo.CreationTime If Date.Now >= createDate.AddDays(7) Then My.Computer.FileSystem.DeleteFile("t:\PowderedLogs\TrackNumLogPowdered.txt") End If Try Dim TimeStamp As String TimeStamp = Date.Now() If My.Computer.FileSystem.FileExists("t:\PowderedLogs\TrackNumLogPowdered.txt") = False Then My.Computer.FileSystem.WriteAllText("t:\PowderedLogs\TrackNumLogPowdered.txt", String.Empty, False) My.Computer.FileSystem.WriteAllText("t:\PowderedLogs\TrackNumLogPowdered.txt", Environment.NewLine + LogText + " - " + TimeStamp, True) Else My.Computer.FileSystem.WriteAllText("t:\PowderedLogs\TrackNumLogPowdered.txt", Environment.NewLine + LogText + " - " + TimeStamp, True) End If Catch ex As Exception MsgBox("Error: Writing to TrackNumLog") End Try End Sub Now this code is supposed to simply delete and re-create a Log file. It works in the sense that it doesn't create an error. It also will delete and re-create the file but it doesn't change the Create Date. It wipes the file and puts the just the new info, but because it doesn't change the create date, every time the code runs it deletes the files, now if i step through the code and stop right after the delete line of code runs and go and physically check the folder, the file isn't there, then i continue to run the code, and when the code is done, i got back and check the file is there now, AND has a new creation date, now why would it not change the creation date unless i physically go to the folder and look for the file???? Its like the because the file is deleted and created so fast in the code that it doesn't register that its a new file.

    G 1 Reply Last reply
    0
    • K Karma31251

      Public Sub AppendTrackNumLog(ByVal LogText As String) Dim LogInfo As System.IO.FileInfo Dim createDate As DateTime LogInfo = My.Computer.FileSystem.GetFileInfo("t:\PowderedLogs\TrackNumLogPowdered.txt") createDate = LogInfo.CreationTime If Date.Now >= createDate.AddDays(7) Then My.Computer.FileSystem.DeleteFile("t:\PowderedLogs\TrackNumLogPowdered.txt") End If Try Dim TimeStamp As String TimeStamp = Date.Now() If My.Computer.FileSystem.FileExists("t:\PowderedLogs\TrackNumLogPowdered.txt") = False Then My.Computer.FileSystem.WriteAllText("t:\PowderedLogs\TrackNumLogPowdered.txt", String.Empty, False) My.Computer.FileSystem.WriteAllText("t:\PowderedLogs\TrackNumLogPowdered.txt", Environment.NewLine + LogText + " - " + TimeStamp, True) Else My.Computer.FileSystem.WriteAllText("t:\PowderedLogs\TrackNumLogPowdered.txt", Environment.NewLine + LogText + " - " + TimeStamp, True) End If Catch ex As Exception MsgBox("Error: Writing to TrackNumLog") End Try End Sub Now this code is supposed to simply delete and re-create a Log file. It works in the sense that it doesn't create an error. It also will delete and re-create the file but it doesn't change the Create Date. It wipes the file and puts the just the new info, but because it doesn't change the create date, every time the code runs it deletes the files, now if i step through the code and stop right after the delete line of code runs and go and physically check the folder, the file isn't there, then i continue to run the code, and when the code is done, i got back and check the file is there now, AND has a new creation date, now why would it not change the creation date unless i physically go to the folder and look for the file???? Its like the because the file is deleted and created so fast in the code that it doesn't register that its a new file.

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      This is a known problem/effect, and there is a Microsoft article about that you can probably find if you look for it. There is also a previous thread about it here on CP. If you create a file with the same name as a previously deleted file, it will get the same creation date as the previous file.

      Despite everything, the person most likely to be fooling you next is yourself.

      C 1 Reply Last reply
      0
      • G Guffa

        This is a known problem/effect, and there is a Microsoft article about that you can probably find if you look for it. There is also a previous thread about it here on CP. If you create a file with the same name as a previously deleted file, it will get the same creation date as the previous file.

        Despite everything, the person most likely to be fooling you next is yourself.

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        Does this mean if someone uninstalls my program and reinstalls it, it will have the old creation date ? That's helpful to know for doing trial licensing and so on.

        Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups