Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to prevent incorrect (Windows) file time attribute of graphic files produced with graph export

    saving a graph using graph export for the first time under a name such as graphtime.wmf saves the graphic file (windows metafile format in this case) with correct file date and time as is displayed e.g. in windows explorer.
    When re-runing the same code the graph file is updated properly but the file date and time is not updated.
    How can I make Stata to update the file attribute filetime each time a graphic file is replaced by an updated version?

    Code:
    sysuse auto
    hist foreign,  note("Filename: graphtime.wmf, Filedate and time: `c(current_date)' `c(current_time)'")  
    graph export "graphtime.wmf", replace
    I am using
    Stata/SE 15.1 for Windows (64-bit x86-64)
    Windows 10 Pro, Version 1809

    I'd be grateful to receive a hint
    Stephan Brosig

  • #2
    I don't see where your problem comes from. I ran the commands twice, and each time I got a different time (date was the same, of course, because I executed the commands in a short space of time) both in the note and as file properties.

    Comment


    • #3
      Thank you Eric, your test result is a step forward in my search for the cause of the problem: it probably has to do with my windows system or my computer.
      The file time in the file properties remains unchanged when the file is replaced:
      graphtimeScreenshot.pdf
      interestingly: when I generate a copy of the graph file (by applying copy and paste the windows explorer) the new version (with "copy" appended to the file name) has the correct file time in the properties.
      best
      Stephan

      Comment


      • #4
        Stephan, it sounds like your Date column is showing the Date Created attribute. You may right click those headings and add the Date Modified column to compare.

        What I think is happening is that you have created the graph at one point, showing the true time the file was created. Then, everytime you re-save/overwrite the file, without deleting the file in between saves, Windows sees that it's the same file name and treats it as if you have simply edited the file (a perfectly sane behavior on the part of Windows). If you watch the Date Modified after each save, this should reflect the true time the file was re-saved.

        You have already told us that the Date (Created) does show up correctly when making a new file. If the Date Created is important to you, rather than the Date Modified, then you will need to delete the old file before or during do-file execution.

        Comment


        • #5
          Leonardo, when executing the instructions that Stephan posted above (#1), the file is deleted . As I said, when executing the commands in #1, I get the desired result but Stephan doesn't.
          Added on edit: I did not delete the graph between the two executions of the set of commands.

          Comment


          • #6
            Eric, the instructions posted in #1 by Stephan will not delete the file on repeated execution. The file is simply overwritten. From Window's perspective, this looks like any file modification, and therefore it will only update metadata about modification time. An explicit deletion by Stata requires the -rm- command (or its synonym, -erase-). For reference, my system is Windows 10 Pro build 1809 with Stata MP(2) 15.1 64-bit.

            If I run the code once, Creation and Modified Time are the same. Then one minute later, I rerun the same code, and now only the Modified Time is updated.
            Click image for larger version

Name:	test1.PNG
Views:	1
Size:	4.8 KB
ID:	1493746

            As an alternative, you can use the -rm- command to erase the file, or delete it from File Explorer, for example. Then after a small delay for Windows to register the deletion (a few seconds), and the graph is recreated, then the Creation and Modified Times match once again because now it appears to Windows that a file did exist, it was deleted, and a new file was created.

            Example code:
            Code:
            sysuse auto
            hist foreign,  note("Filename: graphtime.wmf, Filedate and time: `c(current_date)' `c(current_time)'")  
            graph export "graphtime.wmf", replace
            graph close _all
            
            sleep 15000 // Snooze 15 seconds to check the time stamps
            
            rm "graphtime.wmf"
            sleep 30000 // give windows a few seconds to update its file index reflecting deletion
            
            // recreate the same file
            hist foreign,  note("Filename: graphtime.wmf, Filedate and time: `c(current_date)' `c(current_time)'")  
            graph export "graphtime.wmf", replace
            graph close _all
            So again the question to Stephan stands, which Time field is being shown (Created or Modified) and does the problem persist after deletion and recreation with a small delay between them?

            Comment


            • #7
              Oh, I see. I thought that Stephan was referring only the date and time on the graph itself, which was not being updated.

              Comment

              Working...
              X