IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Scripts/Batch Discussion :

Identifier puis remplacer une ligne dans un fichier [Batch]


Sujet :

Scripts/Batch

  1. #21
    Membre éprouvé
    Homme Profil pro
    Développeur .NET en devenir
    Inscrit en
    Août 2017
    Messages
    546
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur .NET en devenir
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2017
    Messages : 546
    Points : 1 084
    Points
    1 084
    Par défaut
    Code batch : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    @echo off
    setlocal enableextensions enabledelayedexpansion
     
    set logs="logs_creat.txt"
    if exist %logs% (del %logs%)
     
    set "debut=publishUrl"
    set "nouveauxml=nouveau_fichier.txt"
     
    ::::::::::::: VARIABLE A MODIFIER :::::::::::::
    REM Correspond au nom de fichier avec une ligne à modifier
    set "INTEGRATIONpubxml=C:\Laboratoire\Sources_Developement\developpement-develop\WAS\WAS_SOURCES\Properties\PublishProfiles\INTEGRATION.pubxml"
    echo %INTEGRATIONpubxml% >> %logs%
     
    echo A1 >> %logs%
    REM Modification des noms des sources git
    set "Rep_travail=C:\Laboratoire\Sources_Developement"
    set "Nom_cible=\developpement-develop"
    move "%Rep_travail%%Nom_cible%*" "%Rep_travail%%Nom_cible%" >> %logs%
     
    echo A2 >> %logs%
    REM existence du fichier a modifier
    If not exist "%INTEGRATIONpubxml%" (goto :file_notfound)
     
    REM Correspond à la nouvelle ligne
    set "file_line_replace=    ^<publishUrl^>C:\PVC_TestDeploy_avec_zip\Sources_Developement\developpement-develop\WAS\WAS_SOURCES^</publishUrl^>"
    ::::::::::::: VARIABLE A MODIFIER :::::::::::::
     
    echo A3 >> %logs%
    echo "fichier %INTEGRATIONpubxml% AVANT MODIFICATION" >> %logs%
    type %INTEGRATIONpubxml% >> %logs%
     
    echo A4 >> %logs%
    REM effectuer les modification du fichier 
    	if exist "%nouveauxml%" (del "%nouveauxml%")
     
    echo A41 >> %logs% 
     
    (if exist "%INTEGRATIONpubxml%" (echo %INTEGRATIONpubxml%) else (echo "pas de pubxml"))>> %logs%
     
    for /f "usebackq delims=" %%A in ("%INTEGRATIONpubxml%") do (
     
    echo A42 >> %logs% 
     
    	set "ligne=%%A"
    	set "balise=!ligne:~5,10!"
     
    	(if /i "!balise!"=="%debut%" (echo %file_line_replace%) else (echo.!ligne!))>> %nouveauxml%
     
    )
     
    echo Modification terminee ! >> %logs%
     
    pause
     
    echo A5 >> %logs%
    echo "fichier %INTEGRATIONpubxml% APRES MODIFICATION" >> %logs%
    type %INTEGRATIONpubxml% >> %logs%
     
     
    echo A6 >> %logs%
    endlocal
     
    goto :eof
     
    :file_notfound
    echo Fichier introuvable ! >> %logs%

  2. #22
    Membre averti
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juin 2014
    Messages
    744
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Juin 2014
    Messages : 744
    Points : 336
    Points
    336
    Par défaut
    Ah oui, merci beaucoup, c'est super.

    J'ai juste un dernier petit soucis le script me tranforme le "<!--" en "<--"

  3. #23
    Membre averti
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juin 2014
    Messages
    744
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Juin 2014
    Messages : 744
    Points : 336
    Points
    336
    Par défaut
    Est ce que la disparition du point d'exclamation peut venir du fait que le délimiteur "!" soit déjà utilisé : Je n'ai pas bien compris tout ce que faisait la commande type non plus.

  4. #24
    Membre éprouvé
    Homme Profil pro
    Développeur .NET en devenir
    Inscrit en
    Août 2017
    Messages
    546
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur .NET en devenir
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2017
    Messages : 546
    Points : 1 084
    Points
    1 084
    Par défaut
    Mdr ! La commande type ce n'est pas moi qui l'a ajouté, c'est toi.

    Le point d'exclamation disparaît car c'est un caractère spécial, comme tout caractère spécial il est "interprété" par cmd.exe (comme s'il s'agissait d'une !variable!)
    Je pense avoir une solution pour contourner ce problème mais il faut que je modifie le script pour ajouter une fonction.

  5. #25
    Membre éprouvé
    Homme Profil pro
    Développeur .NET en devenir
    Inscrit en
    Août 2017
    Messages
    546
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur .NET en devenir
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2017
    Messages : 546
    Points : 1 084
    Points
    1 084
    Par défaut
    Je n'ai pas pu tester mais ça devrait être bon :

    Code batch : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    @echo off
    setlocal enableextensions enabledelayedexpansion
     
    set logs="logs_creat.txt"
    if exist %logs% (del %logs%)
     
    set "debut=publishUrl"
    set "nouveauxml=nouveau_fichier.txt"
     
    ::::::::::::: VARIABLE A MODIFIER :::::::::::::
    REM Correspond au nom de fichier avec une ligne à modifier
    set "INTEGRATIONpubxml=C:\Laboratoire\Sources_Developement\developpement-develop\WAS\WAS_SOURCES\Properties\PublishProfiles\INTEGRATION.pubxml"
    echo %INTEGRATIONpubxml% >> %logs%
     
    echo A1 >> %logs%
    REM Modification des noms des sources git
    set "Rep_travail=C:\Laboratoire\Sources_Developement"
    set "Nom_cible=\developpement-develop"
    move "%Rep_travail%%Nom_cible%*" "%Rep_travail%%Nom_cible%" >> %logs%
     
    echo A2 >> %logs%
    REM existence du fichier a modifier
    If not exist "%INTEGRATIONpubxml%" (echo Fichier introuvable ! >> %logs%)
     
    REM Correspond à la nouvelle ligne
    set "file_line_replace=    ^<publishUrl^>C:\PVC_TestDeploy_avec_zip\Sources_Developement\developpement-develop\WAS\WAS_SOURCES^</publishUrl^>"
    ::::::::::::: VARIABLE A MODIFIER :::::::::::::
     
    echo A3 >> %logs%
    echo "fichier %INTEGRATIONpubxml% AVANT MODIFICATION" >> %logs%
    type %INTEGRATIONpubxml% >> %logs%
     
    echo A4 >> %logs%
    REM effectuer les modification du fichier 
    	if exist "%nouveauxml%" (del "%nouveauxml%")
     
    echo A41 >> %logs% 
     
    (if exist "%INTEGRATIONpubxml%" (echo %INTEGRATIONpubxml%) else (echo "pas de pubxml"))>> %logs%
     
    for /f "usebackq delims=" %%A in ("%INTEGRATIONpubxml%") do (
     
    echo A42 >> %logs% 
     
    	set "ligne=%%A"
    	call :ecriture ligne	
     
    )
     
    echo Modification terminee ! >> %logs%
     
    pause
     
    echo A5 >> %logs%
    echo "fichier %INTEGRATIONpubxml% APRES MODIFICATION" >> %logs%
    type %INTEGRATIONpubxml% >> %logs%
     
     
    echo A6 >> %logs%
    endlocal
     
    goto :eof
     
    :ecriture
     
    set "balise=!%1:~5,10!"
    (if /i "!balise!"=="%debut%" (echo %file_line_replace%) else (echo.!%1!))>> %nouveauxml%
     
    goto :eof

  6. #26
    Membre averti
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juin 2014
    Messages
    744
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Juin 2014
    Messages : 744
    Points : 336
    Points
    336
    Par défaut
    Citation Envoyé par barnabe0057 Voir le message
    Mdr ! La commande type ce n'est pas moi qui l'a ajouté, c'est toi.

  7. #27
    Membre averti
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juin 2014
    Messages
    744
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Juin 2014
    Messages : 744
    Points : 336
    Points
    336
    Par défaut
    Non, je n'ai toujours pas mon "!" mais un message d'erreur non bloquant avant le pause : "La syntaxe du nom de fichier, de répertoire ou de volume est incorrecte.
    Appuyez sur une touche pour continuer..."
    Le fichier se crée toujours en sortie mais sans le "!".

  8. #28
    Membre éprouvé
    Homme Profil pro
    Développeur .NET en devenir
    Inscrit en
    Août 2017
    Messages
    546
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur .NET en devenir
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2017
    Messages : 546
    Points : 1 084
    Points
    1 084
    Par défaut
    Cette fois c'est la bonne :

    Code batch : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    @echo off
    setlocal enableextensions disabledelayedexpansion
     
    set logs="logs_creat.txt"
    if exist %logs% (del %logs%)
     
    set "debut=publishUrl"
    set "nouveauxml=nouveau_fichier.txt"
     
    ::::::::::::: VARIABLE A MODIFIER :::::::::::::
    REM Correspond au nom de fichier avec une ligne à modifier
    set "INTEGRATIONpubxml=C:\Laboratoire\Sources_Developement\developpement-develop\WAS\WAS_SOURCES\Properties\PublishProfiles\INTEGRATION.pubxml"
    echo %INTEGRATIONpubxml% >> %logs%
     
    echo A1 >> %logs%
    REM Modification des noms des sources git
    set "Rep_travail=C:\Laboratoire\Sources_Developement"
    set "Nom_cible=\developpement-develop"
    move "%Rep_travail%%Nom_cible%*" "%Rep_travail%%Nom_cible%" >> %logs%
     
    echo A2 >> %logs%
    REM existence du fichier a modifier
    If not exist "%INTEGRATIONpubxml%" (echo Fichier introuvable ! >> %logs%)
     
    REM Correspond à la nouvelle ligne
    set "file_line_replace=    ^<publishUrl^>C:\PVC_TestDeploy_avec_zip\Sources_Developement\developpement-develop\WAS\WAS_SOURCES^</publishUrl^>"
    ::::::::::::: VARIABLE A MODIFIER :::::::::::::
     
    echo A3 >> %logs%
    echo "fichier %INTEGRATIONpubxml% AVANT MODIFICATION" >> %logs%
    type %INTEGRATIONpubxml% >> %logs%
     
    echo A4 >> %logs%
    REM effectuer les modification du fichier 
    	if exist "%nouveauxml%" (del "%nouveauxml%")
     
    echo A41 >> %logs% 
     
    (if exist "%INTEGRATIONpubxml%" (echo %INTEGRATIONpubxml%) else (echo "pas de pubxml"))>> %logs%
     
    for /f "usebackq delims=" %%A in ("%INTEGRATIONpubxml%") do (
     
    echo A42 >> %logs% 
     
    	set "ligne=%%A"
    	call :ecriture ligne	
     
    )
     
    echo Modification terminee ! >> %logs%
     
    pause
     
    echo A5 >> %logs%
    echo "fichier %INTEGRATIONpubxml% APRES MODIFICATION" >> %logs%
    type %INTEGRATIONpubxml% >> %logs%
     
     
    echo A6 >> %logs%
    endlocal
     
    goto :eof
     
    :ecriture
     
    setlocal enabledelayedexpansion
    (if /i "!%1:~5,10!"=="%debut%" (echo %file_line_replace%) else (echo.!%1!))>> %nouveauxml%
    endlocal
     
    goto :eof

  9. #29
    Membre averti
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juin 2014
    Messages
    744
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Juin 2014
    Messages : 744
    Points : 336
    Points
    336
    Par défaut
    Super merci.
    Le résultat est bon.
    J'ai toujours cette erreur malgré tout.
    Je vais refaire des tests cet après midi.

  10. #30
    Membre averti
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juin 2014
    Messages
    744
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Juin 2014
    Messages : 744
    Points : 336
    Points
    336
    Par défaut
    Ca marche, encore merci barnabe!

  11. #31
    Membre éprouvé
    Homme Profil pro
    Développeur .NET en devenir
    Inscrit en
    Août 2017
    Messages
    546
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur .NET en devenir
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2017
    Messages : 546
    Points : 1 084
    Points
    1 084
    Par défaut
    De rien, n'oublie pas de passer le sujet en "résolu"

+ Répondre à la discussion
Cette discussion est résolue.
Page 2 sur 2 PremièrePremière 12

Discussions similaires

  1. Remplacer une ligne dans un fichier texte !
    Par toulouz1 dans le forum VBScript
    Réponses: 23
    Dernier message: 19/07/2017, 10h26
  2. [Batch] Remplacer une ligne dans un fichier modèle
    Par PAB/31/SAB dans le forum Scripts/Batch
    Réponses: 2
    Dernier message: 12/03/2010, 10h16
  3. Remplacer une ligne dans un fichier
    Par mister3957 dans le forum C++
    Réponses: 6
    Dernier message: 31/03/2009, 03h09
  4. Remplacer une ligne dans un fichier de configuration
    Par morgan47 dans le forum Langage
    Réponses: 3
    Dernier message: 08/09/2008, 13h15
  5. Remplacer une ligne dans un fichier ?
    Par FenX. dans le forum Shell et commandes GNU
    Réponses: 2
    Dernier message: 30/05/2008, 10h45

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo