Sign in to follow this  
Followers 0
MaCgyver

Search for a file by date?

13 posts in this topic

I don't know if autoit can do this but this is what I want to do.

Create a script that will copy a file according to the current date and copy it to another folder(server). I can copy the file(s) in this manner WWWW*.*out.FWR, but it has to be for that particular day in order to grad the new files created since the script ran last. The script will be used throughout the day as new files are created.

Share this post


Link to post
Share on other sites



idea... as a start

#include <Date.au3>

$t =  FileGetTime(@Windowsdir & "\Notepad.exe", 1)
$yyyymd = $t[0] & "/" & $t[1] & "/" & $t[2]
$iDateCalc = _DateDiff( 'd',$yyyymd,_NowCalc())

If $iDateCalc > "60" Then
    MsgBox( 4096, "", "File moved... over 60 days old: " & $iDateCalc )
EndIf

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

idea... as a start

#include <Date.au3>

$t =  FileGetTime(@Windowsdir & "\Notepad.exe", 1)
$yyyymd = $t[0] & "/" & $t[1] & "/" & $t[2]
$iDateCalc = _DateDiff( 'd',$yyyymd,_NowCalc())

If $iDateCalc > "60" Then
    MsgBox( 4096, "", "File moved... over 60 days old: " & $iDateCalc )
EndIf

8)

The fileGetTime command should help me build the script. I didnt know it existed.

I need something that basically copies any file that looks like WWWW*.*out.FWR, and the creation date equals today's date.

Edited by MaCgyver

Share this post


Link to post
Share on other sites

The fileGetTime command should help me build the script. I didnt know it existed.

I need something that basically copies any file that looks like WWWW*.*out.FWR, and the creation date equals today's date.

i used the following in one of my scripts

...non relevant code up here

$drive_2 = DriveMapAdd("*","\\" & $backup_server & "\c$\Program Files\CA\BrightStor ARCserve Backup\LOG\cas_user_logs\caroot",0, $username , $password )

FileChangeDir ( $drive_2 )

_RunDOS( "dir *.log /b /o-e /od > logs.txt" )
$lines = _FileCountLines( "logs.txt" )
$latest = FileReadLine( "logs.txt" , $lines )

_FileReadToArray($latest ,$backup)

... rest of script here

it maps a drive to a fileserver that is using arcserve. lists the files by name and date order to a txt file then reads the name of the last file to a variable that i use for the rest of the script.

simple but effective way of doing this.

Share this post


Link to post
Share on other sites

Craig I will look into what you posted. The following script obviously didn't work but can't something work along these lines?

$TodayDate = __NowCalcDate()

$File = ('c:\WWWW*.*out.FWR')

If $TodayDate = FileGetTime('c:\WWWW*.*out.FWR'1) Then

FileCopy('$File, c:\test\test')

Exit

EndIf

Share this post


Link to post
Share on other sites

i used the following in one of my scripts

...non relevant code up here

$drive_2 = DriveMapAdd("*","\\" & $backup_server & "\c$\Program Files\CA\BrightStor ARCserve Backup\LOG\cas_user_logs\caroot",0, $username , $password )

FileChangeDir ( $drive_2 )

_RunDOS( "dir *.log /b /o-e /od > logs.txt" )
$lines = _FileCountLines( "logs.txt" )
$latest = FileReadLine( "logs.txt" , $lines )

_FileReadToArray($latest ,$backup)

... rest of script here

it maps a drive to a fileserver that is using arcserve. lists the files by name and date order to a txt file then reads the name of the last file to a variable that i use for the rest of the script.

simple but effective way of doing this.

I think I will use what you have here. Thanks

Share this post


Link to post
Share on other sites

I think I will use what you have here. Thanks

no worries - i did put it in the ideas forum for listing files by date but havent checked back in a while.

Share this post


Link to post
Share on other sites

no worries - i did put it in the ideas forum for listing files by date but havent checked back in a while.

Thanks...

I'm having problem with _filereadarray.

I'm still pretty knew to this. Am I correct in thinking the _FileReadArray line reads the name of the file to copy and copies it the file to a dir? or does it just read and copies the name?

Share this post


Link to post
Share on other sites

i cant find "filereadarray"

FileReadToArray()... reads "a" file into an array

FileListToArray() lists the files in a directory to an array

there is no copying performed

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

i cant find "filereadarray"

FileReadToArray()... reads "a" file into an array

FileListToArray() lists the files in a directory to an array

there is no copying performed

8)

Thanks.....

I'm going home now....when I get there i will figure out what command i need to get the correct file from the log and copy the file to the new directory.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

taken from Lesson #6 in my "Welcome to Autoit 1-2-3"

; includes
#include <GuiConstants.au3>
#include <file.au3>

;****************** FILE LOCATION **********

$File_loc = @ScriptDir & "\"
$File_type = "*.txt"

;********************************************


; create the GUI.
$win = GUICreate("File List/View Demo", 614, 370)
; set the font for the GUI
GUISetFont(9, 400, -1, "MS Sans Serif")
; create buttons.
$btnList = GUICtrlCreateButton("&List Files", 10, 330, 75, 25)
$btnView = GUICtrlCreateButton("&View File", 85, 330, 75, 25)
; create the left list.
$TutorItList = GUICtrlCreateList("", 10, 10, 150, 330)
; create the right edit.
$TutorItEdit = GUICtrlCreateEdit("Please select a tutorial from the list to your left.", 175, 10, 420, 345, $ES_AUTOVSCROLL + $ES_READONLY + $ES_MULTILINE + $WS_VSCROLL)
; set the edit colors.
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUICtrlSetColor(-1, 0x000000)
; set focus to the edit.
GUICtrlSetState($TutorItList, $GUI_FOCUS)
; show the GUI.
GUISetState()

; start the loop.
While 1
; listen for a message
    $msg = GUIGetMsg()
; using select/case for the message
    Select
        Case $msg = $GUI_EVENT_CLOSE 
            Exit
        Case $msg = $btnList
            Set_tutor()
        Case $msg = $btnView
            View_tutor()
; end the selections        
    EndSelect
    
WEnd

; Function to populate the left list.
Func Set_tutor()
    $TutList = _FileListToArray ($File_loc, $File_type, 1); list files to an array.
    If (Not IsArray($TutList)) Or (@error = 1) Then
        MsgBox(262208, "Tutor Error", "No Files\Folders Found.   ", 5)
        Return
    EndIf
    GUICtrlSetData($TutorItList, ""); set list to empty.
    For $x = 1 To $TutList[0]; for loop to place the files in the list.
        GUICtrlSetData($TutorItList, (StringTrimRight($TutList[$x], 4)) & "|", 1); string trim the last 4 characters ( .txt )
    Next
EndFunc   

; Function to populate the right edit.
Func View_tutor()
    $s_text = GUICtrlRead($TutorItList); read the selected file to a variable.
    If $s_text = "" Then Return
    $n_text = StringTrimLeft($File_type, 1)
    $s_text = $File_loc & $s_text & $n_text; set the location of the file.
    Dim $Tut_text
    If Not _FileReadToArray($s_text, $Tut_text) Then; read the file to an array.
        MsgBox(4096, "Tutor Error", " Error reading log to Array     error:" & @error)
        Return
    EndIf
    GUICtrlSetData($TutorItEdit, ""); set the edit to empty.
    For $x = 1 To $Tut_text[0]; for loop to place the read file into the edit.
        GUICtrlSetData($TutorItEdit, $Tut_text[$x] & @CRLF, 1)
    Next
EndFunc

hope that helps

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Edit:

Revised it, stuck it in Scripts and Scraps: http://www.autoitscript.com/forum/index.php?showtopic=23083

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

This worked out for me.

Func _FileCountLines($sFilePath)

Local $N = FileGetSize($sFilePath) - 1

If @error Or $N = -1 Then Return 0

Return StringLen(StringAddCR(FileRead($sFilePath, $N))) - $N + 1

EndFunc ;==>_FileCountLines

Func _RunDOS($sCommand)

Return RunWait(@ComSpec & " /C " & $sCommand, "", @SW_HIDE)

EndFunc ;==>_RunDOS

;$drive_2 = ("\\sv000bkexample\bnkexample\spool" )

;FileChangeDir ('c:\test')

;FileChangeDir ('\\sv000bkexample\bnkexample\spool')

;FileChangeDir ($drive_2)

_RunDOS( "dir \\sv000bkexample\bnkexample\spool\WWWW*.*fwr /b /o-e /od > \\sv000wire03\BTD011\logs.txt" )

sleep(1000)

$lines = _FileCountLines( "\\sv000wire03\BTD011\logs.txt" )

$latest = FileReadLine( "\\sv000wire03\BTD011\logs.txt" , $lines )

FileCopy('\\sv000bkexample\bnkexample\spool\'& $latest, '\\sv000wire03\BTD011\'& $latest)

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  
Followers 0