Jump to content
Sign in to follow this  
grimmlock

Getting file Modified date

Recommended Posts

Good Morning,

I modified this code that I found on Autoit forums to display the information that I need, however there is one thing that I would like help with.

Is there a way to modify this, so that the code looks at all the files inside "folder2" and then have $b display the date of the most recently modified file?

Here is the code I have...

Local $a = FileGetTime("C:\folder1\folder\testing1.txt", 0)
Local $b = FileGetTime("C:\folder1\folder2", 0)
local $c = FileGetTime("C:\folder1\folder3\testing2.txt", 0)

Local $atd = $a[1] & "/" & $a[2] & "/" & $a[0]
Local $btd = $b[1] & "/" & $b[2] & "/" & $b[0]
Local $ctd = $c[1] & "/" & $c[2] & "/" & $c[0]

If MsgBox(4, "Creation date of ...", "Update Files?" & @CRLF & @CRLF & "file1" & " -- " & $atd & @CRLF & @CRLF & "folder1" & " -- " & $btd & @CRLF & @CRLF & "file2" & " -- " & $ctd) = 6 Then
_Copying()
EndIf

Thanks

Grimm


Thanks

Grimm

Share this post


Link to post
Share on other sites

#include <File.au3>

Local $a = FileGetTime("C:\folder1\folder\testing1.txt", 0)

$last = 0
$sFolder = "C:\folder1\folder2"
If @Error = 1 Then exit
$aFiles = _FileListToArray($sFolder , "*" , 1)

for $i = 1 to $aFiles[0]
$time = filegettime($sFolder & "\" & $aFiles[$i] , 0 , 1)
If $time > $last Then
$b = $aFiles[$I] & " modified: " & $time
$last = $time
EndIf
next

msgbox (0 , '' , $b)

local $c = FileGetTime("C:\folder1\folder3\testing2.txt", 0)

Local $atd = $a[1] & "/" & $a[2] & "/" & $a[0]
Local $btd = $b[1] & "/" & $b[2] & "/" & $b[0]
Local $ctd = $c[1] & "/" & $c[2] & "/" & $c[0]

If MsgBox(4, "Creation date of ...", "Update Files?" & @CRLF & @CRLF & "file1" & " -- " & $atd & @CRLF & @CRLF & "folder1" & " -- " & $btd & @CRLF & @CRLF & "file2" & " -- " & $ctd) = 6 Then
_Copying()
[size=4]EndIf[/size]

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

Thank you boththose, I just have1 error and 1 question.

I get this error after the

msgbox (0, '', $b:)
Local $btd = $b[1] & "/" & $b[2] & "/" & $b[0]

Local $btd = $b^ ERROR

Error: Subscript used with non-array variable.

Question: How do I adjust the time / date for $b to display just the month/day/year?

Thanks

Grimm

Edited by grimmlock

Thanks

Grimm

Share this post


Link to post
Share on other sites

sorry i just copied all your stuff back blindly, here it is by itself

#include <File.au3>


$last = 0
$sFolder = "C:\folder1\folder2"
If @Error = 1 Then exit
$aFiles = _FileListToArray($sFolder , "*" , 1)

for $i = 1 to $aFiles[0]
$time = filegettime($sFolder & "\" & $aFiles[$i] , 0 , 1)
If $time > $last Then
$newfile = $aFiles[$I]
$last = $time
EndIf
next

$b = filegettime($sFolder & "\" & $newfile)

Local $btd = $b[1] & "/" & $b[2] & "/" & $b[0]
msgbox(0, '' , $btd)
Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

For some reason this works on my computer but no one elses

#include <File.au3>

Local $a = FileGetTime("\\192.168.26.17\it\My Scripting Workshop\My Utility\ADStaff\staff.txt", 0)

$last = 0
$sFolder = "\\192.168.26.17\it\My Scripting Workshop\My Utility\DHCP"
If @Error = 1 Then exit
$aFiles = _FileListToArray($sFolder , "*" , 1)

for $i = 1 to $aFiles[0]
$time = filegettime($sFolder & "\" & $aFiles[$i] , 0 , 1)
If $time > $last Then
$b = $aFiles[$I] & " modified: " & $time
$last = $time
EndIf
next

msgbox (0 , '' , $b)

;=============================

Local $c = FileGetTime("C:\Program Files\My Utility\ADStaff\staff.txt", 0)

$last = 0
$sFolder = "C:\Program Files\My Utility\DHCP"
If @Error = 1 Then exit
$aFiles = _FileListToArray($sFolder , "*" , 1)

for $i = 1 to $aFiles[0]
$time = filegettime($sFolder & "\" & $aFiles[$i] , 0 , 1)
If $time > $last Then
$d = $aFiles[$I] & " modified: " & $time
$last = $time
EndIf
next

msgbox (0 , '' , $d)

Local $atd = $a[1] & "/" & $a[2] & "/" & $a[0]
Local $btd = $b[1] & "/" & $b[2] & "/" & $b[0]
Local $ctd = $c[1] & "/" & $c[2] & "/" & $c[0]
Local $dtd = $d[1] & "/" & $d[2] & "/" & $d[0]

MsgBox(0, "Creation date of ...", "server" & $atd & $btd & @CRLF & @CRLF & $ctd & $dtd)

Thanks

Grimm

Edited by grimmlock

Thanks

Grimm

Share this post


Link to post
Share on other sites

Where does it fail? right at the start? does $a return anything?


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

If I run it ... using the editor no errors show up. And if I simply run it normally by right clicking on the script and clicking on Run Script nothing happens. I can see, using Task Manager, that something tries to run, but then it just disappears from Task Manager, which means, I assume, it ran successfully however the msgbox never shows up.

I have tried to get results from doing a msgbox(0, '', $a) and nothing shows up.

Thanks

Grimm


Thanks

Grimm

Share this post


Link to post
Share on other sites

grimmlock,

Just offering another alternative. This creates a temp file of all files modified after a date you specify in the named directory and all sub-directories.

#include <file.au3>

local $compdate = '20130220'                            ; list any files modified after this date
local $dir      = 'k:\autoit\'                          ; this directory and all subdirectories

local $aDir     = dirgetsize($dir,1), $st = timerinit(), $sPString

ConsoleWrite('Running ' & $aDir[1] & ' files' & @LF)

local $fl = _TempFile(default,default,'.txt')
filewrite( $fl,do_files($dir) )
ConsoleWrite('Time for complete process = ' & round(timerdiff($st)/1000,4) & ' seconds' & @LF)
shellexecutewait($fl)
filedelete($fl)

func do_files($sdir)

    if stringright($sdir,1) <> '\' then $sdir &= '\'

    local $files = filefindfirstfile($sdir & '*.*')

    if $files = -1 then
        $sPString &= stringformat( '%-100s %-30s \n', $sdir, 'No files found' )
        return
    endif

    while 1

        $file = filefindnextfile($files)
        if @error then exitloop
        if @extended then do_files($sdir & $file)
        if stringleft(filegettime($sdir & $file,0,1),8) > $compdate then $sPString &= stringformat( '%-100s %-30s \n',$sdir & $file, filegettime($sdir & $file,0,1) )

    WEnd

    return $sPString

endfunc

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

So I started from scratch and by adding the DriveMapAdd I was able to get better output. However now, the error is with this line

"Autoit Error

Line 48:

Local $btd = $b[1] & "/" & $b[2] & "/" & $b[0]

Local $btb = $b^error

Error: Subscript used with non-array variable."

Any ideas?

Below is the code

#include <file.au3>

DriveMapAdd("y:", "\\192.168.26.17\IT")

;~ Sleep(1000)
Local $a = FileGetTime("y:\My Scripting Workshop\My Utility\ADStaff\staff.txt", 0)

$last = 0
$sFolder = "y:My Scripting Workshop\My Utility\DHCP"
If @Error = 1 Then exit
$aFiles = _FileListToArray($sFolder , "*" , 1)

for $i = 1 to $aFiles[0]
$time = filegettime($sFolder & "\" & $aFiles[$i] , 0 , 1)
If $time > $last Then
$b = $aFiles[$I] & " modified: " & $time
$last = $time
EndIf
next

;~ msgbox (0 , '' , $b)

Local $c = FileGetTime("C:\Program Files\My Utility\ADStaff\staff.txt", 0)

$hlast = 0
$hFolder = "C:\Program Files\My Utility\DHCP"
If @Error = 1 Then exit
$hFiles = _FileListToArray($hFolder , "*" , 1)

for $i = 1 to $hFiles[0]
$htime = filegettime($hFolder & "\" & $hFiles[$i] , 0 , 1)
If $htime > $hlast Then
$d = $hFiles[$I] & " modified: " & $htime
$hlast = $htime
EndIf
next

msgbox (0 , '' , $d)

Local $atd = $a[1] & "/" & $a[2] & "/" & $a[0]
Local $btd = $b[1] & "/" & $b[2] & "/" & $b[0]
Local $ctd = $c[1] & "/" & $c[2] & "/" & $c[0]
;~Local $dtd = $d[1] & "/" & $d[2] & "/" & $d[0]

MsgBox(0, "Creation date of ...", "server" & @CRLF & @CRLF & $atd &  " ----- " & $ctd)

Thanks!

Grimm


Thanks

Grimm

Share this post


Link to post
Share on other sites

$b is a simple variable, it's not an array in your script. That's why you get the error.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By nacerbaaziz
      it recomended to use the builten function
      _DateDiff
       
       
       
      hello autoit team
      i made a simple function to help me get the difference between to date
      i liked to share it with you
      the paramatrs of this function
      is firstdate and lastedate
      the two params is as the following
      year/month/day hours:minuts:seconds
      here is the function
       
      #include <date.au3> func _dateBetween($s_firstDate, $s_lastDate = default) if not (StringRegExp($s_firstDate, "((\d{4})\/(\d{2})\/(\d{2})\s(\d{2})\:(\d{2})\:(\d{2}))", 0) = 1) then Return SetError(1, 0, 0) if $s_lastDate = default then $s_lastDate = @year & "/" & @mon & "/" & @mday & " " & @hour & ":" & @min & ":" & @sec if not (StringRegExp($s_lastDate, "((\d{4})\/(\d{2})\/(\d{2})\s(\d{2})\:(\d{2})\:(\d{2}))", 0) = 1) then Return SetError(2, 0, 0) local $a_FirstSplitDate = StringSplit(StringRegExpReplace($s_firstDate, "((.*)\s(.*))", "$2"), "/", 2) local $a_FirstSplitTime = StringSplit(StringRegExpReplace($s_firstDate, "((.*)\s(.*))", "$3"), ":", 2) local $a_lastSplitDate = StringSplit(StringRegExpReplace($s_lastDate, "((.*)\s(.*))", "$2"), "/", 2) local $a_LastSplitTime = StringSplit(StringRegExpReplace($s_lastDate, "((.*)\s(.*))", "$3"), ":", 2) local $i_firstDateValue = _DateToDayValue($a_FirstSplitDate[0], $a_FirstSplitDate[1], $a_FirstSplitDate[2]) local $i_LastDateValue = _DateToDayValue($a_LastSplitDate[0], $a_LastSplitDate[1], $a_LastSplitDate[2]) if $i_firstDateValue > $i_LastDateValue then Return SetError(3, 0, 0) local $i_totalDays = $i_LastDateValue-$i_firstDateValue if not ($i_totalDays = 0) then if $a_FirstSplitTime[0] <= $a_lastSplitTime[0] then $i_totalDays += 1 $a_lastSplitTime[0] -= $a_FirstSplitTime[0] elseIf $a_FirstSplitTime[0] > $a_lastSplitTime[0] then if $i_totalDays > 0 then $i_totalDays -= 1 $a_FirstSplitTime[0] -= $a_lastSplitTime[0] endIf endIf endIf local $i_totalYears = 0 if $i_totalDays >= 365 then While $i_totalDays >= 365 $i_totalYears += 1 $i_totalDays -= 365 Wend endIf local $i_TotalMonths = 0 if $i_totalDays >= 30 then While $i_totalDays >= 30 $i_totalMonths += 1 $i_totalDays -= 30 Wend endIf local $i_totalWeeks = 0 if $i_totalDays >= 7 then While $i_totalDays >= 7 $i_totalWeeks += 1 $i_totalDays -= 7 Wend endIf $i_totalSeconds = ((($a_FirstSplitTime[0]*60)*60)+($a_FirstSplitTime[1]*60)+($a_FirstSplitTime[2]))-((($a_lastSplitTime[0]*60)*60)+($a_lastSplitTime[1]*60)+($a_LastSplitTime[2])) local $minus = "" if $i_totalSeconds < 0 then $minus = "-" $i_totalSeconds = StringReplace($i_totalSeconds, "-", "") endIf local $i_totalHours = 0 if $i_totalSeconds >= 3600 then While $i_totalSeconds >= 3600 $i_totalHours += 1 $i_totalSeconds -= 3600 Wend endIf local $i_totalminuts = 0 if $i_totalSeconds >= 60 then While $i_totalSeconds >= 60 $i_totalminuts += 1 $i_totalSeconds -= 60 Wend endIf local $a_arrayReturn[7] $a_arrayReturn[0] = $i_totalYears $a_arrayReturn[1] = $i_totalMonths $a_arrayReturn[2] = $i_totalWeeks $a_arrayReturn[3] = $i_totalDays $a_arrayReturn[4] = $minus & $i_totalHours $a_arrayReturn[5] = $minus & $i_totalminuts $a_arrayReturn[6] = $minus & $i_totalSeconds return $a_arrayReturn endFunc  
      here is an example
       
       
      $a_calc = _dateBetween("2015/02/12 23:00:05", "2030/02/12 23:25:50") msgBox(64, "result", StringFormat("the difference is : %i years and %i months and %i weeks and %i days and %i hours and %i minuts and %i seconds", $a_calc[0], $a_calc[1], $a_calc[2], $a_calc[3], $a_calc[4], $a_calc[5], $a_calc[6]))  
      am waiting for your comments
      with my greetings
    • By Zedna
      #include <WinAPI.au3> $text = FileReadLastChars("C:\Program Files\AutoIt3\Include\Array.au3", 1024) MsgBox(0, 'FileReadLastChars', $text) Func FileReadLastChars($sFile, $nChars)     Local $nBytes     $tBuffer = DLLStructCreate("char["&$nChars&"]")     $hFile = _WinAPI_CreateFile($sFile, 2, 2) ; open for read     _WinAPI_SetFilePointer($hFile, -1 * $nChars, 2) ; from end     _WinAPI_ReadFile($hFile, DLLStructGetPtr($tBuffer), $nChars, $nBytes)     _WinAPI_CloseHandle($hFile)     Return DLLStructGetData($tBuffer, 1) EndFunc ; included as standard UDF since AutoIt 3.2.13.6 version Func _WinAPI_SetFilePointer($hFile, $iPos, $iMethod = 0)     $aResult = DllCall( "kernel32.dll", "long", "SetFilePointer", "hwnd", $hFile, "long", $iPos, "long_ptr", 0, "long", $iMethod)     If @error Then Return SetError(1, 0, -1)     If $aResult[0] = -1 Then Return SetError(2, 0, -1) ; $INVALID_SET_FILE_POINTER = -1     Return $aResult[0] EndFunc ;==>_WinAPI_SetFilePointer Here is my topic about _WinAPI_SetFilePointer()
       
      EDIT: simpler version compatible with latest AutoIt
      $text = FileReadLastChars("C:\Program Files\AutoIt3\Include\Array.au3", 1024) MsgBox(0, 'FileReadLastChars', $text) Func FileReadLastChars($sFile , $nChars) $hFile = FileOpen($sFile, 0) ; open for read FileSetPos($hFile, -1 * $nChars, 2) ; from end $sRet = FileRead($hFile) FileClose($hFile) Return $sRet EndFunc  
    • By Jahar
      Hi All,
      Please help me on how to fetch date/time of last windows 10 system restore point using autoit? Basically its about querying the last restore point.
    • By TheDcoder
      Hi everyone,
      I am bit stumped as to why I am not able to set the time in the Date control
      #include <DateTimeConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Example() Func Example() GUICreate("My GUI get date", 200, 200, 800, 200) Local $idDate = GUICtrlCreateDate("1953/04/25", 10, 10, 185, 20, $DTS_TIMEFORMAT) ; to select a specific default format Local $sStyle = "HH:mm:ss" GUICtrlSendMsg($idDate, $DTM_SETFORMATW, 0, $sStyle) ; Set time Local $iRet = GUICtrlSetData($idDate, '13:33:37') ConsoleWrite('GUICtrlSetData returned ' & ($iRet = 1 ? 'success' : 'failure') & @CRLF) GUISetState(@SW_SHOW) ; Loop until the user exits. While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd MsgBox($MB_SYSTEMMODAL, "Time", GUICtrlRead($idDate)) EndFunc ;==>Example The documentation for GUICtrlSetData clearly mentions that it uses the same format as GUICtrlRead:
      But I get failure
      What gives?
      Thanks for the help in advance!
    • By Scriptmaster
      <NEWBIE ALERT>
      Is it possible to unzip a zip file in Autoit without using a dll!
      My script downloads a zip file to a temporary directory (successfully) and it must be unzipped to (Or moved to after unzip) another a folder which just happens to be
      @scriptdir & "file.exe" Thanks in advance
×
×
  • Create New...