Finding the last modified date using a Macro?

Finding the last modified date using a Macro?

3
NewbieNewbie
3

    Aug 28, 2008#1

    Is it possible to have a Macro locate the last modified date in the properties of a file? Adding copyright dates in files that did not have anything for copyright in the file when it was created, I need a way of accessing the last modified date out of the properties and add in the year that it was last saved. Any ideas would be appreciated.

    6,603548
    Grand MasterGrand Master
    6,603548

      Aug 29, 2008#2

      No, not directly. jorrasdk has already written a script which does something similar - see Active Document date & time. Here is a suggestion for a macro.

      You have to create a user tool with the command line

      dir "%f"

      The tool options must be set to capture the output and replace the existing selection in the current file. Important is that none of the 2 save options is enabled for that tool.

      Next you can write the macro. The macro checks if the date is missing in the current text file. If this is the case, it should move to top of the file and insert something very special there which can be later found again. Next it selects the first character of this special string and runs the user tool - the DIR command.

      The selected character is replaced now by the output of the DIR command. The macro moves the cursor back to top of the file and first checks, if the DIR command successfully returned the data of this file. If the DIR command could not find the file because you run the macro on a new edit window instead of a file, it does nothting special. But if DIR returned the data of the file the macro searches now for the date string and copies it for example to user clipboard 9.

      Then the macro moves back to top of the file and selects everything from here to end of the special string (= captured DIR output + special string) and deletes it. You can now continue with whatever you want to do. Here is an example for that macro.

      The macro property Continue if a Find with Replace not found or Continue if search string not found must be checked for this macro.

      InsertMode
      ColumnModeOff
      HexOff
      UnixReOff
      Clipboard 9
      ClearClipboard
      Top
      "#!#!#!#"
      Top
      StartSelect
      Key RIGHT ARROW
      EndSelect
      RunTool "case-sensitive name of the user tool with the DIR command"
      Top
      Find MatchCase RegExp "%File Not Found"
      IfNotFound
      Find RegExp "%[0-3][0-9].[01][0-9].[12][0-9][0-9][0-9]"
      IfFound
      Copy
      EndIf
      EndIf
      Top
      Find Select "!#!#!#"
      Delete

      Add UnixReOn or PerlReOn (v12+ of UE) at the end of the macro if you do not use UltraEdit style regular expressions by default - see search configuration. Macro command UnixReOff sets the regular expression option to UltraEdit style.

      Don't forget to switch back to the Windows clipboard before the macro exits!

      The output of the DIR command is on my English Windows XP for German (Austria):

      Code: Select all

       Volume in drive F is TEMP
       Volume Serial Number is 28E3-127F
      
       Directory of F:\Temp
      
      29.08.2008  13:30                 4 Test.txt
                     1 File(s)              4 bytes
                     0 Dir(s)  20.543.111.168 bytes free
      The 2 regular expression finds in the macro depend on the format of the output of the DIR command.

      Well, you could develop a batch file or a Visual Basic Script which returns directly on a call with the current file name the last modification date in the format you need. Then you could call this batch/script as user tool and don't need a macro.
      Best regards from an UC/UE/UES for Windows user from Austria

      3
      NewbieNewbie
      3

        Aug 29, 2008#3

        Thank you Mofi for your help, I am able to get the proper year pulled back into the file, I am wondering now if there is a way to do it to multiple files in a folder?

        6,603548
        Grand MasterGrand Master
        6,603548

          Aug 31, 2008#4

          There is not much difference between getting the year of one file or all files in the folder. The command line of the user tool must be changed to dir *.* and the working directory of the user tool must be %p - WITHOUT double quotes!

          Now DOS command DIR returns the list of all files in the folder of the active file. The macro must be adapted to evaluate all the dates from the file list returned by DIR.
          Best regards from an UC/UE/UES for Windows user from Austria