Jump to content

get time


Recommended Posts

hey ,

i need to get the time for a particular file,i did this but its not showing the time . this is my code .. please help me

Local $win = @ScriptDir &"\Test\*.log"

$ch= FileFindFirstFile($win)

While 1

Local $file = FileFindNextFile($ch)

If @error Then ExitLoop

MsgBox(4096, "File:", $file)

WEnd

Local $t = FileGetTime($file)

If Not @error Then

Local $yyyymd = $t[0] & "/" & $t[1] & "/" & $t[2]

MsgBox(0, "Creation date of notepad.exe", $yyyymd)

EndIf

Link to comment
Share on other sites

Use AUTOIT CODE!

Two ways of many ways:

#include <File.au3> ; _FileListToArray

Find_with_Array()
Find_Without_Array()

Func Find_with_Array()
 Local $search = _FileListToArray(@ScriptDir, "*.jpg", 1) ; Only for files
 If @error = 4 Then ; File not found
  MsgBox(16, "Error", "Files not found")
  Return
 EndIf
 For $x = 1 To $search[0]
  Local $t = FileGetTime(@ScriptDir & "\" & $search[$x], 1)
  MsgBox(0, "Creation date of " & $search[$x], $t[0] & "/" & $t[1] & "/" & $t[2])
 Next
EndFunc   ;==>Find_with_Array

Func Find_Without_Array()
 Local $search_v2 = FileFindFirstFile(@ScriptDir & "\" & "*.jpg")
 If $search_v2 = -1 Then ; File not found
  MsgBox(16, "Error", "Files not found")
  Return
 EndIf
 While 1
  Local $file = FileFindNextFile($search_v2)
  If @error Then ExitLoop
  Local $t = FileGetTime($file, 1)
  MsgBox(0, "Creation date of " & $file, $t[0] & "/" & $t[1] & "/" & $t[2])
 WEnd
EndFunc   ;==>Find_Without_Array
Edited by OliverA

I'M QUIT FROM THIS FORUM!

It was fun until it lasted, hope on my future way i can't find people that offend without any reason ( i was called lazy and parasitic, and everyone agreed...United we stand, divided we fall ) just for fun because don't have anything to do in the life, without knowing anything about the person who write, noone forced to post, noone forced to help.

From the top of the from their very great superiority they not go down to my level, that people can not spread the knowledge but you have to learn by yourself.

In what way? It's easy...just search on google

For that people, wish you the best way,

Oliver Astone

Link to comment
Share on other sites

  • Moderators

bhargavik,

Why use the clumsy FileFindFirst/NextFile combo when there is a UDF to all the work for you? ;)

This should do the trick: :)

#include <Array.au3>
#include <File.au3>

$sRoot = @ScriptDir & "\Test"
$sMask = "*.log"

$aList = _FileListToArray($sRoot, $sMask, 1)

Global $aFileTime[UBound($aList)][2]

For $i = 1 To $aList[0]
    $aTime = FileGetTime($sRoot & "\" & $aList[$i])
    $aFileTime[$i][0] = $aList[$i]
    $aFileTime[$i][1] = $aTime[0] & "/" & $aTime[1] & "/" & $aTime[2]
Next

_ArrayDisplay($aFileTime)

All clear? :)

M23

Edited by Melba23
Amended code - see below

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

The reason it was not working is because you search until an error occurs (If @error Then ExitLoop). After the error occurs you try to use the search information which failed The creation time of the failed file search name doesn't exist. :)

I might as well post my example even though I'm too late.

#include <File.au3>

Local $win = @ScriptDir &"\Test\"
Local $aFileList = _FileListToArray($win, "*.log", 1)

Local $t, $yyyymd
For $i = 1 To $aFileList[0]
    $t = FileGetTime($win & $aFileList[$i])
    $yyyymd = $t[0] & "/" & $t[1] & "/" & $t[2]
    MsgBox(0, "Creation date of " & $aFileList[$i], $yyyymd)
Next

@Melba Your code contains a slight oversight.

Edited by czardas
Link to comment
Share on other sites

  • Moderators

czardas,

Your code contains a slight oversight

Do you mean I should have done this:

Global $aFileTime[UBound($aList)][2] = [[$aList[0]]]

to fill the [0] element? :huh:

If not, then pray do tell. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

czardas,

You are quite correct - thanks for pointing it out. I was testing on files within @ScriptDir and so did not notice. :>

Above post amended. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...