Page 1 sur 1
[R] Problème de variable dans fonction
Posté : mer. 28 mai 2008 11:13
par sergio
bonjour,
mon problème : je n'arrive pas à changer la "valeur" d'une variable en passant à un autre fonction.
ce que je cherche à faire :
fonction1
je cherche dans un repertoire sur un serveur tous les fichiers ini
fonction2
je recupere le fichier ini et je lis la premiere section "Binaires"
si les binaires existes ok je pase à la lecture de la deuxieme section "Dialogues"
sinon je passe au fichier ini suivant (fonction1) .
fonction3
ensuite je lis la deuxieme section "Dialogues"
et la je recopie avec "robocopy" les differents repertoires indiqué dans cette section.
fonction4 fin
les fonctions testés une apres l'autre fonctionnent, quand je veux enchainer la fonction 1 avec les autres je ne conserve "qu"une valeur" et je boucle desssus.
merci par avance pour votre aide
le code :
► Afficher le texte
Code : Tout sélectionner
#cs ----------------------------------------------------------------------------
AutoIt Version: 3.2.12.0
Author: Sergio
Script Function:
Vérification des versions et installation des dialogues en fonctions des profils
------------------------------------------------------------------------------------------
fonction recherche :
#include<_FileListToArrayNew2h.au3>
; _FileListToArray3($sPath, $sFilter = "*", $iFlag = 0, $iRecurse = 0, $iBaseDir = 1, $sExclude = "")
$ar_Array = _FileListToArray3 ("c:\", "*.odt", 1, 1, 1,"Temp|TMP")
_ArrayDisplay($ar_Array, "Liste fichier") ; Ceci est facultatif, c'est juste pour afficher la liste des fichiers.
$sPath = Chemin de recherche
$sFilter = Filtre de recherche (*.au3 ou Script?.au3 ...)
$iFlag = 0=Retourne fichier et répertoire, 1=Retourne que les fichiers, 2=Retourne que les répertoires.
$iRecurse = Recherche récursive (0=Non 1=Oui)
$iBaseDir = Inclus le chemin de base (0=Non 1=Oui)
$sExclude = Liste des exclusions, séparées par le caractère '|' (Alt Gr + 6).
------------------------------------------------------------------------------------------
#ce ----------------------------------------------------------------------------
#include<_FileListToArrayNew2h.au3>
$PID = ("robocopy.exe")
$REP_ORIG = "\\serveurinstall\appli\repertoireacopier\"
$REP_DEST = "c:\appli\"
$DomainUserName = "user"
$DomainName = "domain"
$UserPassword = "pwd"
$REP_INI = "\\serveur2\dossier$\Appli\"
$LOG = FileOpen("\\serveur2\dossier$\Logs\test.txt", 1)
_trouve_ini ()
; listage des fichiers *.ini dans le répertoire
func _trouve_ini ()
$FicIni = _FileListToArray3 ($REP_INI, "*.ini", 1, 1, 1,"")
;visualisation des fichiers *.ini
;_ArrayDisplay($FicIni, "Liste fichier")
Dim $FicIni
For $x = 1 to $FicIni[0]
Msgbox(0,"localisation fichier :" , $FicIni[$x])
Global $reference = $FicIni[$x]
_trouve_bin ($reference)
Next
EndFunc;_trouve_ini
; recherche des executables (binaires) servant de référece pour chaque profil indiqué dans le fichier *.ini section Binaires
func _trouve_bin ($reference)
Msgbox(0,"localisation fichier :" , $reference )
$var = IniReadSection($reference, "Binaires")
If @error Then
MsgBox(4096, "", "Erreur Fichier INI inexistant.")
Fin()
EndIf
For $i = 1 To $var[0][0]
if FileExists ($var[$i][1]) Then
MsgBox(4096, "", "COOL il existe : " & $var[$i][1])
; lecture suite
Else
MsgBox(4096, "", "il manque le fichier: " & $var[$i][1])
; si manque un executable passer au fichier ini suivant
_trouve_ini ()
EndIf
Next
_copy_dialog ()
EndFunc;_trouve_bin ()
; Copie des dialogues pour chaque profil indiqué dans le fichier *.ini section Dialogues
func _copy_dialog ()
$vari = IniReadSection($reference, "Dialogues")
If @error Then
MsgBox(4096, "", "Erreur Fichier INI inexistant.")
Fin()
EndIf
For $b = 1 To $vari[0][0]
RunAsWait ( $DomainUserName, $DomainName, $UserPassword, 1, 'c:\Windows\robocopy.exe' & " " & $REP_ORIG & $vari[$b][1] & " " & $REP_DEST & $vari[$b][1] & " " & "/MIR /R:1 /W:1", "c:\TMP", @SW_MAXIMIZE)
If $LOG = -1 Then
MsgBox(0, "Erreur", "impossible d'ouvrir le fichier.")
Fin()
EndIf
FileWriteLine($LOG, @ComputerName & ";" & $reference & ";" & "mis à jour le" & ";" & @MDAY & "/" & @MON & "/" & @YEAR & @CRLF)
FileClose($LOG)
Next
_lance_appli ()
EndFunc;_copy_dialog ()
;Lancement de l'application
Func _lance_appli ()
If ProcessExists($PID) = 0 Then ShellExecute("C:\appli\lancement\appli.exe")
Fin()
EndFunc;_lance_appli
; Fonction de sortie du script.
Func Fin()
Exit
EndFunc;Fin ()
Re: [..] Problème de variable dans fonction
Posté : mer. 28 mai 2008 15:07
par ani
bonjour sergio,
excuse moi, mais çà fait bien la troisème fois que je modifie ton titre (tu oublie la balise [..] voir ce (
lien )) pourquoi tu le modifie ?
Pour ton post, je ne pourrait aider, trop de difficulté, voilàvoilà
Re: [..] Problème de variable dans fonction
Posté : mer. 28 mai 2008 16:55
par sergio
bonjour ani,
Je vous prie de m'excuser je n'ai pas modifié le titre j'essayais de modifier la "colorisation" du code pour que ce soit plus lisible. car j'avais commencé avec forumcolor.
je n'avais pas vu pour la balise [..] dans le titre, j'en étais à peine à la balise [R]

Re: [..] Problème de variable dans fonction
Posté : mer. 28 mai 2008 20:22
par ani
ok ok autant pour moi,
Pour la coloration du code, l'administration a suspendu cette partie pour un allegemement.
je jette un oeil a votre code, mais je ne promet rien
Re: [..] Problème de variable dans fonction
Posté : mer. 28 mai 2008 22:44
par Tlem
ani a écrit :Pour la coloration du code, l'administration a suspendu cette partie pour un allegemement.
Il n'est pas interdit d'utiliser la coloration pour présenter un code (Au contraire).
Simplement, si d'autres utilisateurs doivent reprendre le code en entier pour les corrections ... il vaut mieux passer par la balise de code classique (Inutile de charger la base de donnée pour rien

).
Re: [..] Problème de variable dans fonction
Posté : jeu. 29 mai 2008 06:34
par Greenhorn
Hi,
I don't understand all of your code, but maybe you mean something like this here ...
► Afficher le texte
Code : Tout sélectionner
#include<_FileListToArrayNew2h.au3>
Global $pidRoboCopy = ("robocopy.exe")
Global $REP_ORIG = "\\serveurinstall\appli\repertoireacopier\"
Global $REP_DEST = "c:\appli\"
Global $DomainUserName = "user"
Global $DomainName = "domain"
Global $UserPassword = "pwd"
Global $REP_INI = "\\serveur2\dossier$\Appli\"
Global $LOG = FileOpen("\\serveur2\dossier$\Logs\test.txt", 1)
Global $aFichiersIni
; listage des fichiers *.ini dans le répertoire
$aFichiersIni = _FileListToArray3 ($REP_INI, "*.ini", 1, 1, 1,"")
For $i = 1 To $aFichiersIni[0]
_trouve_bin ($aFichiersIni[$i])
If @error Then ContinueLoop
Next
; recherche des executables (binaires) servant de référece pour chaque profil indiqué dans le fichier *.ini section Binaires
func _trouve_bin ($reference)
Msgbox(0,"localisation fichier :" , $reference )
$var = IniReadSection($reference, "Binaires")
If @error Then
;~ MsgBox(4096, "", "Erreur Fichier INI-Section inexistant.") ; the file EXISTS, but maybe not the section !
Return SetError(1)
EndIf
For $i = 1 To $var[0][0]
if FileExists ($var[$i][1]) Then
MsgBox(4096, "", "COOL il existe : " & $var[$i][1])
; $var[$i][1] <- what's in here ???
; lecture suite
_copy_dialog ($reference)
If @error Then ContinueLoop
Else
MsgBox(4096, "", "il manque le fichier: " & $var[$i][1])
; si manque un executable passer au fichier ini suivant
;~ _trouve_ini ()
EndIf
Next
EndFunc;_trouve_bin ()
; Copie des dialogues pour chaque profil indiqué dans le fichier *.ini section Dialogues
func _copy_dialog ($reference)
$vari = IniReadSection($reference, "Dialogues")
If @error Then
;~ MsgBox(4096, "", "Erreur Fichier INI inexistant.")
Return SetError(1)
EndIf
For $b = 1 To $vari[0][0]
RunAsWait ( $DomainUserName, $DomainName, $UserPassword, 1, 'c:\Windows\robocopy.exe "' & $REP_ORIG & $vari[$b][1] & '" "' & $REP_DEST & $vari[$b][1] & '" /MIR /R:1 /W:1', "c:\TMP", @SW_MAXIMIZE)
If $LOG = -1 Then
MsgBox(0, "Erreur", "impossible d'ouvrir le fichier.")
Fin()
EndIf
FileWriteLine($LOG, @ComputerName & ";" & $reference & ";" & "mis à jour le" & ";" & @MDAY & "/" & @MON & "/" & @YEAR & @CRLF)
FileClose($LOG)
Next
_lance_appli ($pidRoboCopy)
EndFunc;_copy_dialog ()
;Lancement de l'application
Func _lance_appli ($PID)
If ProcessExists($PID) = 0 Then ShellExecute("C:\appli\lancement\appli.exe")
Fin()
EndFunc;_lance_appli
; Fonction de sortie du script.
Func Fin()
Exit
EndFunc;Fin ()
EDIT:
What I wanna point to is that it's better to create functions with a return value and then work with the result of the function.
If you could post an example.ini I could give you a better example for a solution.
Maybe also interesting ...
http://www.autoitscript.com/forum/index ... bocopy+gui
Greetz
Greenhorn
Re: [..] Problème de variable dans fonction
Posté : ven. 30 mai 2008 09:20
par sergio
thank you Greenhorn for your help,
the guideline that you gave me is good.
in a few lines that I try to do:
we have a software with several possible profiles. There is a common part (directories identical) and directories.
in a repertoire I have a number of file. ini representing different profiles (you can add)
in this file ini I have two sections:
the first list which binaries specific profile.
the second section is the name of the directory profile.
what I try to do:
1 - read the files. Ini one by one
2 - reading the section binary: if all executables ini file in question exists in this case go to Step 3 if not move to Step 1 and read another file ini
3 - reading the section directory and launching the copy robocopy
4 - end
-----------------------------------------------------------------------------------
file.ini
Code : Tout sélectionner
#Executables à tester et Dialogue à copier
[Binaires]
bin1 = C:\appli\grd\amospse\amospse.exe
bin2 = C:\apppli\ggh\amppat\amppat.exe
[Dialogues]
dial1 = gaa
dial2 = gac
dial3 = gad
dial4 = ggh
dial5 = grd
dial6 = windows
-----------------------------------------------------------------------------------
Re: [..] Problème de variable dans fonction
Posté : ven. 30 mai 2008 13:17
par Greenhorn
Thank you very much for your detailed reply, my dear.
I'll try to give you an example script ...
Greetz
Greenhorn
Re: [..] Problème de variable dans fonction
Posté : lun. 02 juin 2008 15:59
par Greenhorn
Hi sergio,
I have changed the script a little bit, maybe you find it's more practicable ...
Code : Tout sélectionner
; step 1
; listage des fichiers *.ini dans le répertoire
$aFichiersIni = _FileListToArray3 ($REP_INI, "*.ini", 1, 1, 1,"")
For $i = 1 To $aFichiersIni[0]
;step 2
_trouve_bin ($aFichiersIni[$i])
If @error Then ContinueLoop
Next
func _trouve_bin ($reference)
$aDir = IniReadSectionNames($reference)
If @error Then
Return SetError(1)
EndIf
For $i = 1 To $aDir[0]
$aBinaries = IniReadSection($reference, $aDir[$i])
For $ii = 1 to $aBinaries[0][0]
If Not FileExists ($aBinaries[$i][1]) Then
$OK = 0
ExitLoop
Else
$OK = 1
EndIf
Next
If $OK Then
RunAsWait ( $DomainUserName, _
$DomainName, _
$UserPassword, _
1, _
'c:\Windows\robocopy.exe "' & $REP_ORIG & $aBinaries[$i] & '" "' & $REP_DEST & $aBinaries[$i] & '" /MIR /R:1 /W:1', _
"c:\TMP", @SW_MAXIMIZE)
If @error Then MsgBox(266256, Default, 'Error copying !', 5)
EndIf
Next
EndFunc
#cs - example.ini
[C:\appli\grd]
bin1=amospse\amospse1.exe
bin2=amospse\amospse2.exe
[C:\appli\ggh]
bin1=amppat\amppat1.exe
bin1=amppat\amppat2.exe
#ce
Salut
Greenhorn
Re: [..] Problème de variable dans fonction
Posté : mar. 03 juin 2008 11:30
par sergio
dear Greenhorn,
thank you for your valuable assistance,
I have no experience in the development of application, made a few small scripts.
I left with an idea, but you will allow me just to reach my goals.
greetings

Re: [..] Problème de variable dans fonction
Posté : mer. 04 juin 2008 01:50
par Greenhorn
Moin, Moin sergio,
naturally it must be:
Code : Tout sélectionner
If Not FileExists ($aDir[$i] & '\' & $aBinaries[$i][1]) Then
$OK = 0
ExitLoop
Else
$OK = 1
EndIf
Salut

Re: [..] Problème de variable dans fonction
Posté : mer. 04 juin 2008 10:29
par sergio
danke viele GreenHorn
