Sushmitha Posted December 1, 2009 Share Posted December 1, 2009 Hi, I'm new to AutoIt and i'm stuck with this problem. Please help. I'm trying to read all the files present in a particular folder and i'm using FileFindFirstFile & FileFindNextFile.(i.e $search = FileFindFirstFile("*.txt")) It works perfectly fine when there is a certain fixed number of files before starting the search. (i.e if 5 files are present in the folder before starting the search it loops through all 5 files) but if any new file is added after starting the program, it does't read that new file! Is it so that FileFindFirstFile makes a list of all the files present or is the list made dynamically during FileFindNextFile?? Please help!!! Link to comment Share on other sites More sharing options...
99ojo Posted December 1, 2009 Share Posted December 1, 2009 (edited) Hi, Is it so that FileFindFirstFile makes a list of all the files present or is the list made dynamically during FileFindNextFile?? It seems, that the search handle get the names static...... Because i don't know exactly the behaviour of the FileFind functions, i would script like this: expandcollapse popup#include <file.au3> #include <array.au3> Global $sourcepath = "c:\test", $arfiles, $arnewfile [1] _getfile () Func _getfile () Local $arfilestemp $arfiles = _FileListToArray ($sourcepath, "*.txt", 1) $count = $arfiles [0] For $i = 1 To UBound ($arfiles) - 1 ; Are there new files? $artempfiles = _FileListToArray ($sourcepath, "*.txt", 1) If $artempfiles [0] > $count Then $count = $artempfiles [0] _getdiff ($arfilestemp) Else _dowhatyouwantfunction ($sourcepath & "\" & $arfiles [$i]) EndIf Next EndFunc ;parameter: array with filenames of txt files Func _getdiff ($array) For $i = 1 To UBound ($array) - 1 ;Find which file is new If _ArraySearch ($arfiles, $array [$i]) = -1 Then ;Is file really new? If _ArraySearch ($arnewfile, $array [$i]) = -1 Then $arnewfile [Ubound ($arnewfile) - 1] = $array [$i] ReDim $arnewfile [UBound ($arnewfile) + 1] _dowhatyouwantfunction ($sourcepath & "\" & $array [$i]) EndIf EndIf Next EndFunc ;paramter: full path to file Func _dowhatyouwantfunction ($fpathfile) MsgBox (0,"", $fpathfile) EndFunc ;-)) Stefan Edited December 1, 2009 by 99ojo Link to comment Share on other sites More sharing options...
Sushmitha Posted December 1, 2009 Author Share Posted December 1, 2009 (edited) Thanks 99ojo so much for the quick reply This is indeed a good way of parsing for updated files and it works great But I have a slightly different requirement, i.e I delete the file on which action is performed so that I don't read it again and again. So here is one more way of doing it, for those who want to achieve it using FileFindFirstFile & FileFindNextFile. Dim $errorID $path = "c:\test" FileChangeDir ($path); While 1 $search = FileFindFirstFile("*.txt") $file = FileFindNextFile($search) If @error Then ExitLoop _dowhatyouwantfunction($file) WEnd Func _dowhatyouwantfunction ($fpathfile) MsgBox (0,"", $fpathfile) FileDelete ( $path & "\" & $fpathfile ) EndFunc Cheers, Sush Edited December 1, 2009 by Sushmitha Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now