EricF Posted May 1, 2008 Share Posted May 1, 2008 (edited) Hello, I use FileFindNextFile() to move files to another directory. I would like to show a message after the last file. @error always return 0, even at the end of the loop. How to proceed ? I use AutoIt 3.2.10 on Win XP. Edited May 5, 2008 by EricF Link to comment Share on other sites More sharing options...
FreeRider Posted May 1, 2008 Share Posted May 1, 2008 Hi EricF, I you want to obtain quick help, don't forget to include your script/function... otherwise it's sometimes hard to see where is the problem... Bye FreeRiderHonour & Fidelity Link to comment Share on other sites More sharing options...
rasim Posted May 2, 2008 Share Posted May 2, 2008 Hello, I use FileFindNextFile() to move files to another directory. I would like to show a message after the last file. @error always return 0, even at the end of the loop. How to proceed ? I use AutoIt 3.2.10 on Win XP. Hi! Try this: $path = "c:\temp" Dim $last $search = FileFindFirstFile($path & "\*.*") If $search = -1 Then Exit While 1 $file = FileFindNextFile($search) If @error Then MsgBox(0, "Find file", $last & " is a last file") ExitLoop EndIf $last = $path & "\" & $file ConsoleWrite($path & "\" & $file & @LF) WEnd FileClose($search) Link to comment Share on other sites More sharing options...
EricF Posted May 2, 2008 Author Share Posted May 2, 2008 The problem is that It don't works with the result of @error. While 1 $nom_fichier = FileFindNextFile($liste_fichiers) If @error Then ExitLoop If $date_split[1] = 01 Then;On vérifie si la date du jour est 01 ;On vérifie que la date de modification des fichiers SQL est identique à la date du jour (en cas de non transfert des fichiers SQL) If StringMid(FileGetTime($dossier_temp_sql & $nom_fichier, 0, 1), 1, 8) = $date_split[3] & $date_split[2] & $date_split[1] Then MsgBox(0, "test", "nom : " & $nom_fichier & " - La date correspond !") ;FileMove($dossier_temp_sql & $nom_fichier, $destination, 9);flag 9 : crée la destination si elle n'existe pas et écrase les fichiers existants ;if @error Then MsgBox(0, "fin", @error) <------ problem here ;EndIf I would like to show a message after the last move. Link to comment Share on other sites More sharing options...
James Posted May 2, 2008 Share Posted May 2, 2008 While 1 $nom_fichier = FileFindNextFile($liste_fichiers) If @error Then ExitLoop If $date_split[1] = 01 Then;On vérifie si la date du jour est 01 ;On vérifie que la date de modification des fichiers SQL est identique à la date du jour (en cas de non transfert des fichiers SQL) If StringMid(FileGetTime($dossier_temp_sql & $nom_fichier, 0, 1), 1, 8) = $date_split[3] & $date_split[2] & $date_split[1] Then MsgBox(0, "test", "nom : " & $nom_fichier & " - La date correspond !") ;FileMove($dossier_temp_sql & $nom_fichier, $destination, 9);flag 9 : crée la destination si elle n'existe pas et écrase les fichiers existants ;if @error = 1Then MsgBox(0, "fin", @error) <------ problem here ;EndIf Not sure, but you can try it. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
EricF Posted May 2, 2008 Author Share Posted May 2, 2008 (edited) You only change ;if @error = 1Then It's not the problem because 1. I already try it, 2. this line is commented, and doesn't affect the code. The line MsgBox(0, "fin", @error) return a 0 value for @error after each file. I already have tested with true. Edited May 2, 2008 by EricF Link to comment Share on other sites More sharing options...
MikeP Posted May 2, 2008 Share Posted May 2, 2008 (edited) rasim is right... just apply it to your code : While 1 $nom_fichier = FileFindNextFile($liste_fichiers) If @error Then ExitLoop If $date_split[1] = 01 Then If StringMid(FileGetTime($dossier_temp_sql & $nom_fichier, 0, 1), 1, 8) = $date_split[3] & $date_split[2] & $date_split[1] Then MsgBox(0, "test", "nom : " & $nom_fichier & " - La date correspond !") FileMove($dossier_temp_sql & $nom_fichier, $destination, 9) EndIf EndIf EndIf $dernier_fichier = $nom_fichier WEnd MsgBox(0,"","Dernier fichier déplacé : "&$dernier_fichier) tip : don't put any instructions between your FileFindNextFile line and your line testing the @error or you won't get the result you want... Edited May 2, 2008 by MikeP Link to comment Share on other sites More sharing options...
EricF Posted May 3, 2008 Author Share Posted May 3, 2008 Thanks. But the message must appear after the last file move, and only if FileMove is run. Right now, the message always appear. Link to comment Share on other sites More sharing options...
EricF Posted May 5, 2008 Author Share Posted May 5, 2008 (edited) Problem resolved ! I have used _FileListToArray() and _ArrayMax() to have the number of files in the directory. Then, I have initialized a counter, incremented after each file move. Then, I verify that the counter is equal to the _ArrayMax() value. expandcollapse popup;On cherche le premier fichier SQL $liste_fichiers = FileFindFirstFile($dossier_temp_sql & "*.sql") #include <File.au3> #include <Array.au3> ;On regroupe la liste des fichiers du dossier dans un Array $liste_fichiers_array = _FileListToArray($dossier_temp_sql, "*.sql", 1) ;On récupère la valeur maximale dans l'Array (= nb de fichiers du dossier) $liste_fichiers_array_total = _ArrayMax($liste_fichiers_array, 0) ;MsgBox(0, "index max", $liste_fichiers_array_total);pour test Array ;Si aucun n'est présent dans le dossier, on affiche un message If $liste_fichiers = -1 Then SoundPlay("H:\WINDOWS\Media\chord.wav") MsgBox(0, "Error", "Erreur : aucun fichier dans le dossier " & $dossier_temp_sql & " !") Exit EndIf $nb_fichiers = 0;Initialisation du compteur de fichiers ;Si la fonction FileFindFirstFile renvoie 1 (true), on cherche le fichier suivant et on boucle pour le déplacement des fichiers dans un nouveau dossier While 1 $nom_fichier = FileFindNextFile($liste_fichiers) If @error Then ExitLoop If $date_split[1] = 05 Then;On vérifie si la date du jour est 01 ;On vérifie que la date de modification des fichiers SQL est identique à la date du jour (en cas de non transfert des fichiers SQL) If StringMid(FileGetTime($dossier_temp_sql & $nom_fichier, 0, 1), 1, 8) = $date_split[3] & $date_split[2] & $date_split[1] Then ;MsgBox(0, "test", "nom : " & $nom_fichier & " - compteur : " & $nb_fichiers & " - La date correspond !");pour test FileMove($dossier_temp_sql & $nom_fichier, $destination, 9);flag 9 : crée la destination si elle n'existe pas et écrase les fichiers existants ;On incrémente le compteur de fichiers $nb_fichiers = $nb_fichiers+1 ;On vérifie que le compteur de fichiers est égal au nombre de fichiers du dossier if $liste_fichiers_array_total = $nb_fichiers Then SoundPlay("H:\WINDOWS\Media\chimes.wav") MsgBox(0, "Copie des sauvegardes SQL", "Déplacement terminé !", 3) EndIf Else SoundPlay("H:\WINDOWS\Media\chord.wav") MsgBox(0, "Copie des sauvegardes SQL", "Erreur : la date des fichiers SQL n'est pas la date du jour ! Le déplacement des fichiers ne se fera pas.") ;MsgBox(0, "test", "nom : " & $nom_fichier & " - La date ne correspond pas : " & StringMid(FileGetTime($dossier_temp_sql & $nom_fichier, 0, 1), 1, 8) & " - " & $date_split[3] & $date_split[2] & $date_split[1] & " !");pour test ExitLoop EndIf EndIf WEnd Edited May 5, 2008 by EricF 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