Jump to content

list of new files


handyt2
 Share

Recommended Posts

hi experts.. 

I have a landing directory that receives files from other systems. some generate new filename, but some use the same filename & overwriting the old ones.

every 1hr, I want my AutoIT to detect new files only into a variable.

previously, I thought of running dir /b > filelist.txt, so i can compare the last hour filelist.txt with the current list.. but this can't work with files of the same names.

so, I created a [work] folder, xcopy /d [landing]*.csv to [work]*.csv 

this command gave me the list of new files, but i need to copy the files first..

any suggestions for better ways..?

---

once i have the list of new files in variable/array, i will need to loop & run other processing.. this part is not a problem with me.

 

thanx in advance..

 

Link to comment
Share on other sites

Do the ones that are overwritten get a new create or modified date/time?

What happens to the files after they are processed in the landing dir?

I can get around this...

I've never used XCOPY but from the doc it looks like the smallest granularity you can get is one day so that does not seem to be a viable path given that you want to monitor files every hour.

I have a small routine that monitors files in a target dir by interval but I need answers to 1 and 2 above to adapt it to your needs.

edit: clarification

Edited by 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

Link to comment
Share on other sites

handyt2,

This may be of some use.  It monitors $Target_Dir for any files created or modified since $Last_Scan.  See comments in code...

#include <date.au3>
#include <file.au3>
#include <array.au3>

; Used for testing Process_Files() function
;~ HotKeySet('^a', 'testing')
;~ Func testing()
;~  Process_Files(_NowCalc())
;~ EndFunc   ;==>testing

Local $Target_Dir = 'k:\test' ; folder to monitor
Local $Last_Scan = _NowCalc() ; time of last scan
Local $Scan_Interval = '00:10:00' ; duration to wait in HH:MM:SS
Local $iTmp, $vRET

; convert $Scan_Interval to seconds
Local $iSecWait = StringSplit($Scan_Interval, ':', 2)[0] * 60 * 60 + StringSplit($Scan_Interval, ':', 2)[1] * 60 + StringSplit($Scan_Interval, ':', 2)[2]

While 1

    ; wait till $Scan_Interval has elapsed
    While _DateDiff('s', $Last_Scan, _NowCalc()) < $iSecWait

        ; show remaining time in tooltip
        $iTmp = $iSecWait - _DateDiff('s', $Last_Scan, _NowCalc())
        TraySetToolTip('Time Left to Next Scan  ' & StringFormat('%02i:%02i:%02i', Floor($iTmp / 60 ^ 2), Mod($iTmp / 60, 60), Mod($iTmp, 60)))

        Sleep(1000)

    WEnd

    ; Wait time expired...check for files created / modified since last scan
    $vRET = Process_Files($Last_Scan)

    ; Process returned files
    MsgBox(0, 'Files resulting from scan at ' & $Last_Scan, IsArray($vRET) ? _ArrayToString($vRET) : $vRET, 3)

    ; reset for next scan
    $Last_Scan = _NowCalc()

WEnd

Func Process_Files($LS)

    ConsoleWrite(_Now() & ' Scanning for files newer than ' & $LS & @CRLF)

    ; dump full paths of files, do not include sub-folders
    Local $aFiles = _FileListToArrayRec($Target_Dir, '*', 1, 0, 0, 2)
    If @error = 1 And @extended = 9 Then Return 'No Files Found'

    Local $aFT[UBound($aFiles)][3]

    ; populate $aFT with file path, mod date/time and create date/time in _nowcalc format
    For $1 = 0 To UBound($aFT) - 1
        $aFT[$1][0] = $aFiles[$1]
        $aFT[$1][1] = StringRegExpReplace(FileGetTime($aFT[$1][0], 0, 1), '(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})', '$1/$2/$3 $4:$5:$6')
        $aFT[$1][2] = StringRegExpReplace(FileGetTime($aFT[$1][0], 1, 1), '(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})', '$1/$2/$3 $4:$5:$6')
    Next

    _ArrayDelete($aFT, 0)

    ; delete any entries not created or modified since last scan
    For $1 = UBound($aFT) - 1 To 0 Step -1
        If _DateDiff('s', $LS, $aFT[$1][1]) < 0 And _DateDiff('s', $LS, $aFT[$1][2]) < 0 Then _ArrayDelete($aFT, $1)
    Next

    ; return array of qualifying files or message
    If UBound($aFT) > 0 Then
        Return $aFT
    Else
        Return 'No Files Qualify'
    EndIf

EndFunc   ;==>Process_Files

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

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...