Jump to content
Sign in to follow this  
dannydy

How to Get file "date last saved"

Recommended Posts

dannydy

Hi, i need some help here. basically i was trying to get the file date of modified. But i found that the date modified was different with Date last saved. Thus i need to get this date last save from excel file instead of date modified.

This is my code, the return date was modified date. My file date of modified was 22/5/2012, date of last saved was 28/5/2012 which is today. Note the file was saved in the sharepoint server.

Global Const $ocsfilepath = "My sharePoint pathMy excel file"
Local $ocs = FileGetTime($ocsfilepath,0,0)
ConsoleWrite(_filetimeconverttest($ocs[2],$ocs[1],$ocs[0],$ocs[3],$ocs[4]) & @LF)

Func _filetimeconverttest($gday,$gdate,$gyear, $grab, $fmin)
    If $grab > 12 Then
   $grab = $grab -12
        $x = "PM"
   elseif $grab = 12 Then
   $x = "PM"
   Elseif $grab = 0 Then
   $grab =12
        $x = "AM"
  Else
  $x = "AM"
  EndIf
  $filetimeto = $gday & "/" & $gdate & "/" &$gyear & " " & $grab & ":" & $fmin & $x
Return ($filetimeto)
EndFunc
Edited by dannydy

Share this post


Link to post
Share on other sites
water

Check this UDF. It should give you all the properties of a file.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Xenobiologist

Did you see the other options?

Global Const $ocsfilepath = "c:Dokumente und Einstellungenxf01145Eigene DateienCSVFile_2010-11-02T16_19_41.csv"
Local $ocs = FileGetTime($ocsfilepath, 0, 0)
ConsoleWrite(_filetimeconverttest($ocs[2], $ocs[1], $ocs[0], $ocs[3], $ocs[4]) & @LF)
Local $ocs = FileGetTime($ocsfilepath, 1, 0)
ConsoleWrite(_filetimeconverttest($ocs[2], $ocs[1], $ocs[0], $ocs[3], $ocs[4]) & @LF)
Local $ocs = FileGetTime($ocsfilepath, 2, 0)
ConsoleWrite(_filetimeconverttest($ocs[2], $ocs[1], $ocs[0], $ocs[3], $ocs[4]) & @LF)
Func _filetimeconverttest($gday, $gdate, $gyear, $grab, $fmin)
If $grab > 12 Then
  $grab = $grab - 12
  $x = "PM"
ElseIf $grab = 12 Then
  $x = "PM"
ElseIf $grab = 0 Then
  $grab = 12
  $x = "AM"
Else
  $x = "AM"
EndIf
$filetimeto = $gday & "/" & $gdate & "/" & $gyear & " " & $grab & ":" & $fmin & $x
Return ($filetimeto)
EndFunc   ;==>_filetimeconverttest

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites
dannydy

Thanks a lot water, this UPF was very useful. But it takes sometimes to return the file properties.

Share this post


Link to post
Share on other sites
water

Dannydy,

you can pass the needed property as second parameter so it might be a bit faster.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
dannydy

This is how i do, but it doesnt make any differences.... average it takes 8secs for returning the result.

#include <File.au3> ; only used for the example script, not needed for the UDF
#include <Array.au3> ; only used for the example script, not needed for the UDF
$sFolder="sharepoinMyexcel.xlsx"

ConsoleWrite("File size of = " & _FileGetProperty($sFolder, "size") & @CRLF) ; displays in the console the Size of the file
ConsoleWrite("Modified Date = " & _FileGetProperty($sFolder, "Date last saved") & @CRLF)

Func _FileGetProperty(Const $S_PATH, Const $S_PROPERTY = "")
    Local Const $objShell = ObjCreate("Shell.Application")
    If @error Then Return SetError(3, 0, 0)
    Local $iPropertyCount = 300 ; arbitrary number used, Windows 7 only returns 289 properties, Windows XP only returns 38 (future proofing)
    If StringLeft($S_PATH, 1) = '"' Then StringTrimLeft($S_PATH, 1) ; deletes any quotes around the pathfilename, otherwise will cause errors
    If StringRight($S_PATH, 1) = '"' Then StringTrimRight($S_PATH, 1) ; deletes any quotes around the pathfilename, otherwise will cause errors
    If Not FileExists($S_PATH) Then Return SetError(1, 0, 0)
    Local Const $S_FILE = StringTrimLeft($S_PATH, StringInStr($S_PATH, "", 0, -1))
    Local Const $S_DIR = StringTrimRight($S_PATH, StringLen($S_FILE) + 1)
    Local Const $objFolder = $objShell.NameSpace($S_DIR)
    Local Const $objFolderItem = $objFolder.Parsename($S_FILE)
    If $S_PROPERTY Then
        For $I = 0 To $iPropertyCount
            If $objFolder.GetDetailsOf($objFolder.Items, $I) = $S_PROPERTY Then Return $objFolder.GetDetailsOf($objFolderItem, $I)
        Next
        Return SetError(2, 0, 0)
    EndIf
    ;Local $av_ret[300][2] = [[1]]
   ; For $I = 1 To $iPropertyCount + 1
       ; If $objFolder.GetDetailsOf($objFolder.Items, $I) Then
            ;$av_ret[$I][0] = $objFolder.GetDetailsOf($objFolder.Items, $I - 1)
           ; $av_ret[$I][1] = $objFolder.GetDetailsOf($objFolderItem, $I - 1)
           ; $av_ret[0][0] += 1
        ;EndIf
   ; Next
   ; ReDim $av_ret[$av_ret[0][0] + 1][2]
    ;If Not $av_ret[1][0] Then Return SetError(2, 0, 0)
    ;Return $av_ret
EndFunc   ;==>_FileGetProperty
Edited by dannydy

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×