Jump to content
Sign in to follow this  
grimmlock

Getting file Modified date

Recommended Posts

grimmlock

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
iamtheky

#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
grimmlock

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
iamtheky

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
grimmlock

Thank you boththose, you rock :thumbsup:

Grimm


Thanks

Grimm

Share this post


Link to post
Share on other sites
grimmlock

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
iamtheky

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


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

Share this post


Link to post
Share on other sites
grimmlock

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
kylomas

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
grimmlock

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
BrewManNH

$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  

  • Similar Content

    • VADemon
      By VADemon
      I've encountered a problem with a single file where I cannot retrieve it's Date-time. So far my code has worked well for over 30 files, but this one is a mystery I cannot debug myself due to insufficient Au3 knowledge.
      In line 11 "_Date_Time_FileTimeToArray" is called and for this particular file it sets the @error to 10. I don't know what that error code means, but it's not set by the _Date functions themselves I think.
      Overall, it could be a problem caused by any of the functions below, how can I properly debug this? / Does anybody know a what's causing this?
      _WinAPI_CreateFile() / _Date_Time_GetFileTime() / _Date_Time_FileTimeToArray()
      Func _SetFileTimes($sFilePath) Local $monthNumber[13] = ["", "January", "February", "March", "April", "May", "Juny", "July", "August", "September", "October", "November", "December"] Local $dayNumber[7] = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] Local $fHandle = _WinAPI_CreateFile($sFilePath, 2, 2) ; read-only ; may NOT return a valid date for some reason! TODO Local $fTagFILETIME = _Date_Time_GetFileTime($fHandle) _WinAPI_CloseHandle($fHandle) ; This will return an empty array if theres no valid date $fModTime = _Date_Time_FileTimeToArray($fTagFILETIME[2]) ; last Modified if @error <> 10 then Local $year = $fModTime[2] Local $month = $fModTime[0] Local $day = $fModTime[1] Local $hour = $fModTime[3] Local $min = $fModTime[4] Local $sec = $fModTime[5] Local $ms = $fModTime[6] Local $weekday = $fModTime[7] Global $prettyTimestamp = StringFormat("%s, %s %d, %04d %02d:%02d:%02d", $dayNumber[$weekday], $monthNumber[$month], $day, $year, $hour, $min, $sec) Global $uploadDate = StringFormat("%04d-%02d-%02d", $year, $month, $day) $fModTime = _Date_Time_FileTimeToArray(_Date_Time_FileTimeToLocalFileTime($fTagFILETIME[2])) ; last Modified Local $year = $fModTime[2] Local $month = $fModTime[0] Local $day = $fModTime[1] Local $hour = $fModTime[3] Local $min = $fModTime[4] Local $sec = $fModTime[5] Local $ms = $fModTime[6] Local $weekday = $fModTime[7] ; GetUnixTime accounts for Local time, hence feed it local time Global $unixTimestamp = _GetUnixTime($year &"/"& $month &"/"& $day &" "& $hour&":"& $min &":"& $sec) else Global $prettyTimestamp = "N/A" Global $uploadDate = "" Global $unixTimestamp = "N/A" endif endfunc  
      _GetUnixTime returned the year 1601 start date, showing that $fModTime is probably equal 0. (But Why?)
      The file reports these dates in Explorer, it's on local NTFS drive:
      Created: ‎‎Wednesday, ‎31. ‎Januar ‎2018, ‏‎18:55:02
      Modified: ‎Wednesday, ‎10. ‎Januar ‎2018, ‏‎12:39:23
      Accessed: ‎Wednesday, ‎10. ‎Januar ‎2018, ‏‎12:39:23
    • Jemboy
      By Jemboy
      Hi,
      Ones(some times twice) a month I get an e-mail with zip file, which has price updates from a supplier.
      I have to upload the file to an FTP to get it processed.
      When uploading the file, it will get "timestamped" with the time and date at which time the file was uploaded.
      Normally this is fine, because I mostly upload the file the same day.
      Sometimes it may take 1 or 2 days before I can upload the file.
      For historical purpose, I would like to have the file timestamped with the original date.
      I have tried using:  _FTP_Command ( $hFTPSession, "MFCT YYYYMMDDHHMMSS path") 
      however this command does not work or change the timestamp as I expected.
      Does anyone now a way how I can change the timestamp of a FTP-file?
    • Siryx
      By Siryx
      So what i need is a function that I pass a starting date into and it counts up to the current date. Example:
      2009-05-30
      2009-05-31
      2009-06-01
      ...
      2018-06-18
      How would I do that? I found the Date.au3 in the includes but I can't find anything close to a time object like I'm used to working with in Java. I just need some $date = setDate(2009-05-30) and from there I could just add a day every time. I need this to be in the very format I stated earlier and from what I can see everytime related to date and time is automatically changed to my german locale.
      €: I already tried setDate but instead it changed my PCs clock. Not quite what i was looking for  
    • nacerbaaziz
      By nacerbaaziz

      Hello
      I have a question please
      How to show Islamic date in Autoit
      I mean
      for example
      Ramadan month
      And moharam month ... etc
      I hope my question is clear for you
      Thanks in advance
×