Je suis ennuyé, la première fonction se lance, mais le script continue à tourner en fin de première fonction, et ne quitte pas la fonction dès que la dernière case de la colonne est vide (If $String="" Then Return). Donc mes deux fonctions ne s'enchainent pas malgré mon fichier (_import.txt) qui s'alimente bien jusqu'à la dernière réf présente dans mon csv de départ.
Heu, pour synthétiser, ma fonction X1 se lance parfaitement, et à la fin, pas de message d'erreur, elle continue de tourner, sans passer à la fonction X2.
Je peux fournir le tableau csv et le code complet par mp si besoin.
Code : Tout sélectionner
#include <String.au3>
#include <File.au3>
#include <Date.au3>
X1()
Func X1()
$Line=1
$path=@WorkingDir&"\aaa.csv" ; correspond a un fichier csv de 4 colonnes, A=RefX1, B=urlX1, C=RefX2, D=urlX2
While 1
$String=FileReadLine($path,$Line)
If $String="" Then Return
$Snam= StringSplit($String, ";")
Dim $url =$Snam[2] ;2 = numéro de colonne lue
Dim $hDownload = InetGet($url, @WorkingDir & "\Test.txt", 1, 0)
Dim $sFldr1 = @WorkingDir&"\import\"
Dim $Date_us = _NowCalcDate()
Dim $Date_eu1 = StringRegExpReplace($Date_us, "\A(\d*)/(\d*)/(\d*)","$3/$2/$1")
Dim $Date_eu2 = StringReplace($Date_eu1,"/", "")
Dim $DossierFichier = $sFldr1&$Date_eu2&"_import.txt"
while FileExists("Test.txt")=0
Sleep(200) ; on fait une pause, pour préserver le CPU
WEnd
$File=@WorkingDir & "\Test.txt"
$txt = FileRead($File)
; ISOLATION DES VARIABLES
$string1 = StringRegExp($txt, '\n*.*EUR","price":"(.*)","i|\n*.*EUR","price":(.*),"i', 1) ;PRIX
If IsArray($string1) Then $result = $string1[0]
$string2 = StringRegExp($txt, '\n*Réf : (.*)<\/p>', 1) ;REFERENCE
If IsArray($string2) Then $result = $string2[0]
;CREATION DU DOSSIER ET FICHIER
DirCreate($sFldr1)
$fh = FileOpen($DossierFichier, 1)
If $fh = -1 Then SetError(1, 0, 0)
Local $iWriteFile = FileWriteLine($fh, "X1;"&$Date_eu2&";"&$string1[0]&";"&$string2[0])
Local $iRet = FileClose($fh)
If $iWriteFile = -1 Then SetError(2, $iRet, 0)
FileDelete ("Test.txt")
$Line+=1
WEnd
EndFunc ;X1
X2()
Func X2()
$Line=1
$path=@WorkingDir&"\bbb.csv" ; correspond a un fichier csv de 4 colonnes, A=RefX1, B=urlX1, C=RefX2, D=urlX2
While 1
$String=FileReadLine($path,$Line)
If $String="" Then Return
$Snam= StringSplit($String, ";")
Dim $url =$Snam[4] ;4 = numéro de colonne lue
Dim $hDownload = InetGet($url, @WorkingDir & "\Test.txt", 1, 0)
Dim $sFldr1 = @WorkingDir&"\import\"
Dim $Date_us = _NowCalcDate()
Dim $Date_eu1 = StringRegExpReplace($Date_us, "\A(\d*)/(\d*)/(\d*)","$3/$2/$1")
Dim $Date_eu2 = StringReplace($Date_eu1,"/", "")
Dim $DossierFichier = $sFldr1&$Date_eu2&"_import.txt"
while FileExists("Test.txt")=0
Sleep(200) ; on fait une pause, pour préserver le CPU
WEnd
$File=@WorkingDir & "\Test.txt"
$txt = FileRead($File)
; ISOLATION DES VARIABLES
$string1 = StringRegExp($txt, '\n*var productPrice = (.*);', 1) ;PRIX
If IsArray($string1) Then $result = $string1[0]
$string2 = StringRegExp($txt, "\n*\nvar productReference = '(.*)';", 1) ;REFERENCE
If IsArray($string2) Then $result = $string2[0]
;CREATION DU DOSSIER ET FICHIER
DirCreate($sFldr1)
$fh = FileOpen($DossierFichier, 1)
If $fh = -1 Then SetError(1, 0, 0)
Local $iWriteFile = FileWriteLine($fh, "X2;"&$Date_eu2&";"&$string1[0]&";"&$string2[0])
Local $iRet = FileClose($fh)
If $iWriteFile = -1 Then SetError(2, $iRet, 0)
FileDelete ("Test.txt")
$Line+=1
WEnd
EndFunc ;X2