Je génère par boucle 4 dossiers.
Le but est d'écrire des paramètres, de les utiliser pour exécuter un *.bat qui va nous généré un fichier *.csv.
Jusque là tout est OK.
Ensuite je veux créer une base SQLite dans chaque dossier dans laquelle je stock le contenu de chaque fichier csv pour faire des requêtes.
Mon problème est ici... Ca ne me créer qu'un seul dossier... La boucle stoppe à 1 sans me mettre d'erreur...
Ci-joint mon code.
Merci par avance.
► Afficher le texte
Code : Tout sélectionner
Func _MaFonction()
$iCalc = _DateAdd("n", "-30", _NowCalc())
;D - Add number of days to the given date
;M - Add number of months to the given date
;Y - Add number of years to the given date
;w - Add number of Weeks to the given date
;h - Add number of hours to the given date
;n - Add number of minutes to the given date
;s - Add number of seconds to the given date
$DateStart = StringRegExpReplace(_Now(), '(\d{2})/(\d{2})/(\d{4}) (\d{2}):(\d{2}):(\d{2})', '$3$2$1$4$5$6')
$DateEnd = StringRegExpReplace($iCalc, '(\d{4})/(\d{2})/(\d{2}) (\d{2}):(\d{2}):(\d{2})', '$1$2$3$4$5$6')
;-> Dimensionnement array
Dim $aLine[4][3] = [ _
["Ml-1", "62", "TS20"], _
["Ml-1", "64", "TS20 2"], _
["Ml-2", "62", "TS20"], _
["Ml-2", "64", "TS20 2"]]
For $i = 0 To UBound($aLine) - 1
For $j = 0 To UBound($aLine, 2) - 1
;-> Création des fichiers *.prm ------------------------------
If Not _FileCreate($PathOfCSVFile & "\R006_" & $aLine[$i][0] & "Cell" & $aLine[$i][1] & "\RPT_" & $DateStart & "_" & $aLine[$i][0] & "Cell" & $aLine[$i][1] & ".prm") Then Return
$File = FileOpen($PathOfCSVFile & "\R006_" & $aLine[$i][0] & "Cell" & $aLine[$i][1] & "\RPT_" & $DateStart & "_" & $aLine[$i][0] & "Cell" & $aLine[$i][1] & ".prm", 1)
If $File = -1 Then Return
FileWrite($File, ".............." & @CRLF)
FileWrite($File, ".............." & @CRLF)
FileWrite($File, ".............." & @CRLF)
FileWrite($File, ".............." & @CRLF)
FileWrite($File, ".............." & @CRLF)
FileWrite($File, ".............." & @CRLF)
FileClose($File)
;-> Création des fichiers *.bat associés ------------------------------
If Not _FileCreate($PathOfCSVFile & "\R006_" & $aLine[$i][0] & "Cell" & $aLine[$i][1] & "\RPT_" & $DateStart & "_" & $aLine[$i][0] & "Cell" & $aLine[$i][1] & ".bat") Then Return
$BatFile = FileOpen($PathOfCSVFile & "\R006_" & $aLine[$i][0] & "Cell" & $aLine[$i][1] & "\RPT_" & $DateStart & "_" & $aLine[$i][0] & "Cell" & $aLine[$i][1] & ".bat", 1)
If $BatFile = -1 Then Return
FileWrite($BatFile, ".............." & @CRLF)
FileWrite($BatFile, ".............." & @CRLF)
FileClose($BatFile)
FileCopy(@ScriptDir & "\Ini\sqlnet.ora", $PathOfCSVFile & "\R006_" & $aLine[$i][0] & "Cell" & $aLine[$i][1] & "\", 9)
FileCopy(@ScriptDir & "\Ini\tnsnames.ora", $PathOfCSVFile & "\R006_" & $aLine[$i][0] & "Cell" & $aLine[$i][1] & "\", 9)
Next
RunWait($PathOfCSVFile & "\R006_" & $aLine[$i][0] & "Cell" & $aLine[$i][1] & "\RPT_" & $DateStart & "_" & $aLine[$i][0] & "Cell" & $aLine[$i][1] & ".bat", $PathOfCSVFile & "\R006_" & $aLine[$i][0] & "Cell" & $aLine[$i][1], @SW_HIDE)
Filedelete($PathOfCSVFile & "\R006_" & $aLine[$i][0] & "Cell" & $aLine[$i][1] & "\RPT_" & $DateStart & "_" & $aLine[$i][0] & "Cell" & $aLine[$i][1] & ".bat")
FileDelete($PathOfCSVFile & "\R006_" & $aLine[$i][0] & "Cell" & $aLine[$i][1] & "\sqlnet.ora")
FileDelete($PathOfCSVFile & "\R006_" & $aLine[$i][0] & "Cell" & $aLine[$i][1] & "\tnsnames.ora")
;--Création de la base SQLite--------------------------------------------------------------------
Dim $SQLiteHeader
_FileReadToArray($PathOfCSVFile & "\R006_" & $aLine[$i][0] & "Cell" & $aLine[$i][1] & "\ErrorProtocol_" & $aLine[$i][0] & "Cell" & $aLine[$i][1] & "_Valeurs.csv", $aArrayCSVHeader)
$SQLite = $PathOfCSVFile & "\R006_" & $aLine[$i][0] & "Cell" & $aLine[$i][1] & "\" & $aLine[$i][0] & "Cell" & $aLine[$i][1] & ".SQLite"
_InitSql()
;Récupération de la première ligne du fichier *.csv
$SQLiteHeader = StringReplace($aArrayCSVHeader[1], ";", ",")
_SQLite_Open($SQLite)
If @error > 0 Then Exit MsgBox(16, "SQLite Error", "Impossible de créer la Base de donnée!")
_SQLite_Exec(-1, "CREATE TABLE IF NOT EXISTS DummyTable (" & $SQLiteHeader & ");")
;On insère les valeurs
If $aArrayCSVHeader[0] < 2 Then
MsgBox(16, "", "Aucune valeur dans le fichier csv")
ContinueLoop
Else
For $i = 2 To UBound($aArrayCSVHeader) - 1
$aArrayCSVHeader[$i] = StringReplace($aArrayCSVHeader[$i], ";", ", ")
$aArrayCSVHeader[$i] = StringReplace($aArrayCSVHeader[$i], '"', "'")
_SQLite_Exec(-1, "Insert Into DummyTable(" & $SQLiteHeader & ") VALUES(" & $aArrayCSVHeader[$i] & ");")
Next
EndIf
Next
Else
;..............
EndIf
EndFunc
Func _InitSql()
_SQLite_Startup($sLocalSQLiteDll, False, 1)
If @error Then
MsgBox(0, "Fichier manquant", "Le fichier SQLite3.dll est introuvable!")
Exit
EndIf
$Base_SQLite = _SQLite_Open($SQLite)
If @error > 0 Then
MsgBox(16, "SQLite Erreur", "La base ne peut être chargée!")
Exit
EndIf
OnAutoItExitRegister("_Exit_SQLite")
EndFunc ;==>_InitSql
Func _Exit_SQLite()
_SQLite_Close()
_SQLite_Shutdown()
EndFunc ;==>_Exit_SQLite

