chrisgreece Posted January 5, 2020 Posted January 5, 2020 Hello and happy new year to all! I have a rather stupid question and i have searched everywhere and have done almost everything without a solution. I am trying to find if a folder is added in a certain directory. If it is added i will go on to do some actions. The problem is that while there is no file there my console says correctly "Nothing" but when a file is added its becoming stuck on that case and doesnt want to move on. Nor i can use the directory to add an other file because it is used Here is my code and i got to say that i have tried almost everything expandcollapse popup#include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> Dim $source dim $diki dim $epistrofi Dim $counter $counter = 0 Global $Source="C:\Users\chris\Documents\ΜΕΤΑΓΩΓΩΝ\" Global $diki = FileFindFirstFile($Source & "ΔΙΚΗ\*") Global $epistrofi = FileFindFirstFile($Source & "ΕΠΙΣΤΡΟΦΗ\*") While $counter = 0 While $diki=-1 Global $Source="C:\Users\chris\Documents\ΜΕΤΑΓΩΓΩΝ\" Global $diki = FileFindFirstFile($Source & "ΔΙΚΗ\*") Global $epistrofi = FileFindFirstFile($Source & "ΕΠΙΣΤΡΟΦΗ\*") sleep (1000) ConsoleWrite("ΔΙΚΗ ΜΑΣ: " & $diki & "ΕΠΙΣΤΡΟΦΗ: " & $epistrofi & @LF) WEnd Sleep (2000) $NameDiki1 = FileFindNextFile($diki) Local $diki1 = FileFindFirstFile("C:\Users\chris\Documents\ΜΕΤΑΓΩΓΩΝ\ΔΙΚΗ\" & $NameDiki1 &"\*") $NameDiki2 = FileFindNextFile($diki1) ; A sorted list of all files and folders in the AutoIt installation Global $dir = "C:\Users\chris\Documents\ΜΕΤΑΓΩΓΩΝ\ΔΙΚΗ\" & $NameDiki1 & "\" & $NameDiki2 $dir1="C:\Users\chris\Documents\ΜΕΤΑΓΩΓΩΝ\ΣΤΑΛΜΕΝΑ\ΔΙΚΗ\"& $NameDiki1 IF FileExists($dir1)Then ;EAN ΥΠΑΡΧΕΙ ΤΟΤΕ ΑΠΛΑ ΑΝΤΙΓΡΑΦΗ FileCopy($dir,$dir1 &"\",$FC_OVERWRITE) Else ;ΕΑΝ ΔΕΝ ΥΠΑΡΧΕΙ ΤΟΤΕ ΔΗΜΙΟΥΡΓΟΥΜΕ ΚΑΙΝΟΥΡΙΟ ΦΑΚΕΛΟ DirCreate($dir1) FileCopy($dir,$dir1 &"\",$FC_OVERWRITE) EndIf ConsoleWrite($NameDiki1) DirRemove("C:\Users\chris\Documents\ΜΕΤΑΓΩΓΩΝ\ΔΙΚΗ\" & $NameDiki1,$DIR_REMOVE) Sleep (2000) $diki = -1 ConsoleWrite ("Ο ΦΑΚΕΛΟΣ ΔΙΚΗ ΔΗΜΙΟΥΡΓΗΘΗΚΕ") If FileExists("C:\Users\chris\Documents\ΜΕΤΑΓΩΓΩΝ\ΔΙΚΗ\" & $NameDiki1) Then MsgBox(4096, "ΟΚ", "Exists") Else MsgBox(4096, "ΟΚ", "makas") EndIf WEnd
chrisgreece Posted January 5, 2020 Author Posted January 5, 2020 No worries! i figured it out with a rather unorthodox way! Here it is: i created two identical scripts, compiled them and made them exit once the first loop is finished and run the other script and vice versa! Not really professional but hey ! At least the job is done! expandcollapse popup#include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> Dim $source dim $diki dim $epistrofi Global $Source="C:\Users\chris\Documents\ΜΕΤΑΓΩΓΩΝ\" Global $diki = FileFindFirstFile($Source & "ΔΙΚΗ\*") Global $epistrofi = FileFindFirstFile($Source & "ΕΠΙΣΤΡΟΦΗ\*") While $diki<>-3 or $epistrofi<>-3 While $diki=-1 and $epistrofi=-1 Global $Source="C:\Users\chris\Documents\ΜΕΤΑΓΩΓΩΝ\" Global $diki = FileFindFirstFile($Source & "ΔΙΚΗ\*") Global $epistrofi = FileFindFirstFile($Source & "ΕΠΙΣΤΡΟΦΗ\*") sleep (1000) ConsoleWrite("ΔΙΚΗ ΜΑΣ: " & $diki & "ΕΠΙΣΤΡΟΦΗ: " & $epistrofi & @LF) WEnd Sleep (2000) $NameDiki1 = FileFindNextFile($diki) Local $diki1 = FileFindFirstFile("C:\Users\chris\Documents\ΜΕΤΑΓΩΓΩΝ\ΔΙΚΗ\" & $NameDiki1 &"\*") $NameDiki2 = FileFindNextFile($diki1) While $diki <>-1 $diki=-1 Global $dir = "C:\Users\chris\Documents\ΜΕΤΑΓΩΓΩΝ\ΔΙΚΗ\" & $NameDiki1 & "\" & $NameDiki2 $dir1="C:\Users\chris\Documents\ΜΕΤΑΓΩΓΩΝ\ΣΤΑΛΜΕΝΑ\ΔΙΚΗ\"& $NameDiki1 IF FileExists($dir1)Then ;EAN ΥΠΑΡΧΕΙ ΤΟΤΕ ΑΠΛΑ ΑΝΤΙΓΡΑΦΗ FileCopy($dir,$dir1 &"\",$FC_OVERWRITE) Else ;ΕΑΝ ΔΕΝ ΥΠΑΡΧΕΙ ΤΟΤΕ ΔΗΜΙΟΥΡΓΟΥΜΕ ΚΑΙΝΟΥΡΙΟ ΦΑΚΕΛΟ DirCreate($dir1) FileCopy($dir,$dir1 &"\",$FC_OVERWRITE) EndIf ConsoleWrite($NameDiki1) DirRemove("C:\Users\chris\Documents\ΜΕΤΑΓΩΓΩΝ\ΔΙΚΗ\" & $NameDiki1 & "\",$DIR_REMOVE) Sleep (2000) ConsoleWrite ("Ο ΦΑΚΕΛΟΣ ΔΙΚΗ ΔΗΜΙΟΥΡΓΗΘΗΚΕ") MsgBox(1,"Ok","ΔΙΚΗ") ShellExecute("C:\Users\chris\Documents\ΜΕΤΑΓΩΓΩΝ\test3.exe") Exit ExitLoop WEnd $NameEpistrofi1 = FileFindNextFile($epistrofi) Local $epistrofi1 = FileFindFirstFile("C:\Users\chris\Documents\ΜΕΤΑΓΩΓΩΝ\ΔΙΚΗ\" & $NameEpistrofi1 &"\*") $NameEpistrofi2 = FileFindNextFile($Epistrofi1) While $epistrofi <> -1 Global $dir2 = "C:\Users\chris\Documents\ΜΕΤΑΓΩΓΩΝ\ΕΠΙΣΤΡΟΦΗ\" & $NameEpistrofi1 & "\" & $NameEpistrofi2 $dir3="C:\Users\chris\Documents\ΜΕΤΑΓΩΓΩΝ\ΣΤΑΛΜΕΝΑ\ΕΠΙΣΤΡΟΦΗ\"& $NameEpistrofi1 IF FileExists($dir3)Then ;EAN ΥΠΑΡΧΕΙ ΤΟΤΕ ΑΠΛΑ ΑΝΤΙΓΡΑΦΗ FileCopy($dir2,$dir3 &"\",$FC_OVERWRITE) Else ;ΕΑΝ ΔΕΝ ΥΠΑΡΧΕΙ ΤΟΤΕ ΔΗΜΙΟΥΡΓΟΥΜΕ ΚΑΙΝΟΥΡΙΟ ΦΑΚΕΛΟ DirCreate($dir3) FileCopy($dir2,$dir3 &"\",$FC_OVERWRITE) EndIf DirRemove("C:\Users\chris\Documents\ΜΕΤΑΓΩΓΩΝ\ΕΠΙΣΤΡΟΦΗ\" & $NameEpistrofi1 & "\",$DIR_REMOVE) Sleep (1500) ConsoleWrite ("Ο ΦΑΚΕΛΟΣ ΕΠΙΣΤΡΟΦΗ ΔΗΜΙΟΥΡΓΗΘΗΚΕ") DirCreate("C:\Users\chris\Documents\ΜΕΤΑΓΩΓΩΝ\ΕΠΙΣΤΡΟΦΗ") $epistrofi=-1 MsgBox(1,"Ok","ΕΠΙΣΤΡΟΦΗ") ShellExecute("C:\Users\chris\Documents\ΜΕΤΑΓΩΓΩΝ\test3.exe") Exit WEnd WEnd
Subz Posted January 5, 2020 Posted January 5, 2020 It would have been better to use _FileListToArrayRec to capture all folders and then use For loop to check for the files existence in each of the array items.
chrisgreece Posted January 5, 2020 Author Posted January 5, 2020 Still same issue, i tried that 😕 . Loop gets stuck and does not let me use the folder
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