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 :

Optimisation du code


Sujet :

Scripts/Batch

  1. #1
    Expert éminent

    Homme Profil pro
    Technicien Help Desk
    Inscrit en
    Juillet 2004
    Messages
    2 756
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Technicien Help Desk

    Informations forums :
    Inscription : Juillet 2004
    Messages : 2 756
    Points : 6 686
    Points
    6 686
    Par défaut Optimisation du code
    Bonjour,

    Je souhaiterai optimiser le code suivant :
    Code : 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
    @echo off
    
    if "%1"=="" goto:-h
    if "%1"=="-v" if not "%2"=="" goto:-h
    if "%1"=="-v" if "%2"=="" goto:-v
    if "%1"=="-h" if not "%2"=="" goto:-h
    if "%1"=="-h" if "%2"=="" goto:-h
    if "%1"=="-c" if "%2"=="" goto:-h
    if "%1"=="-c" if "%2"=="%~dpn2" goto:-c
    if "%1"=="-g" if "%2"=="" goto:-h
    if "%1"=="-g" if "%2"=="%~dpn2" goto:-g
    goto:-h
    
    :-c
    echo -c
    goto:eof
    
    :-g
    echo -g
    goto:eof
    
    :-v
    echo -v
    goto:eof
    
    :-h
    echo -h
    goto:eof
    Pourriez-vous me donner un petit coup de main s'il vous plaît?

    Merci
    .Olivier

  2. #2
    Expert éminent

    Homme Profil pro
    Technicien Help Desk
    Inscrit en
    Juillet 2004
    Messages
    2 756
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Technicien Help Desk

    Informations forums :
    Inscription : Juillet 2004
    Messages : 2 756
    Points : 6 686
    Points
    6 686
    Par défaut
    J'ai apporter ces modifications :
    Code : 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
    set "arg=-v -h"
    set "args=-g -c -d -r"
    
    if "%1"=="" (
     goto:-h
    )
    for %%a in (%arg%) do ( 
     if "%1"=="%%a" if "%2"=="" goto:%%a
    )
    if "%2"=="" (
     goto:-h
    )
    for %%a in (%args%) do (
     if "%1"=="%%a" if "%2"=="%~dpn2" goto:%%a
    )
    goto:-h
    
    :-g
    echo -g
    goto:eof
    
    :-c
    echo -c
    goto:eof
    
    :-d
    echo -d
    goto:eof
    
    :-r
    echo -r
    goto:eof
    
    :-v
    echo -v
    goto:eof
    
    :-h
    echo -h
    goto:eof
    Qu'en pensez-vous ?
    .Olivier

  3. #3
    Membre expert
    Avatar de sachadee
    Homme Profil pro
    AMI DU BAT
    Inscrit en
    Janvier 2013
    Messages
    1 478
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Brésil

    Informations professionnelles :
    Activité : AMI DU BAT
    Secteur : Distribution

    Informations forums :
    Inscription : Janvier 2013
    Messages : 1 478
    Points : 3 768
    Points
    3 768
    Par défaut
    Salut Olivier,

    Tu le traînes en longeur ton problème d'argument

    Si ça marche comme tu veux c'est parfait.

    ________________________________
    Un p'tit coup de pouce ça fait toujours plaisir, pensez-y !
    ________________________________

  4. #4
    Expert éminent

    Homme Profil pro
    Technicien Help Desk
    Inscrit en
    Juillet 2004
    Messages
    2 756
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Technicien Help Desk

    Informations forums :
    Inscription : Juillet 2004
    Messages : 2 756
    Points : 6 686
    Points
    6 686
    Par défaut
    Bonjour

    Je le traine en longueur oui en effet et d'ailleurs, je suis confronté à petit soucis avec une fonction :
    Code : 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
    @echo off
    
    set "name=CheckIndex"
    set "ver=1.3"
    
    title %name% %ver%
    
    set "r_val="
    set "arg=-v -h"
    set "args=-g -c -d -r"
    
    if "%1"=="" (
     goto:-h
    )
    for %%a in (%arg%) do ( 
     if "%1"=="%%a" goto:%%a
    )
    if "%2"=="" (
     goto:-h
    )
    for %%a in (%args%) do (
     if "%1"=="%%a" if "%2"=="%~dpn2" goto:%%a
    )
    goto:-h 
    
    :-g
    call:-t val1
    echo %val1%
    echo -g
    goto:eof
    
    :-t
    if exist "%~dpn2" (
     set "%~1=1"
    ) else (
     set "%~1=0"
    )
    goto:eof
    
    :-h
    echo.
    echo Usage: %0 [-v] [-h] ^| [-g] [-c] [-d] [-r] filename
    echo.
    echo -g  - print the contents of directory into the specified file
    echo -c  - compare and create the differential file if needed
    echo -d  - display the contents of the specified file
    echo -r  - remove the specified file
    echo -v  - display version number and exit
    echo -h  - display this help and exit
    goto:eof
    -t test la validité du chemin indiqué mais lorsque j'appelle cette fonction via -g, il indique toujours val1=0. Pour l'exemple, j'ai indiqué -g mais après je vais rajouter -c -d -r qui doivent également fonctionner en parallèle avec la fonction.

    Une idée ? Merki
    .Olivier

  5. #5
    Membre expert
    Avatar de sachadee
    Homme Profil pro
    AMI DU BAT
    Inscrit en
    Janvier 2013
    Messages
    1 478
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Brésil

    Informations professionnelles :
    Activité : AMI DU BAT
    Secteur : Distribution

    Informations forums :
    Inscription : Janvier 2013
    Messages : 1 478
    Points : 3 768
    Points
    3 768
    Par défaut
    Salut,

    Un autre moyen pour tester la validité d'un label :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    if not [%1]==[] findstr /i /r /c:"^[ ]*:%1\>" "%~f0" >nul 2>nul && goto:%1
    goto:-h
    
    ::Source : http://stackoverflow.com/questions/21348579/check-if-label-exists-cmd

    Et dans -g il faut envoyer %2

    ________________________________
    Un p'tit coup de pouce ça fait toujours plaisir, pensez-y !
    ________________________________

Discussions similaires

  1. optimiser le code d'une fonction
    Par yanis97 dans le forum MS SQL Server
    Réponses: 1
    Dernier message: 15/07/2005, 08h41
  2. Optimiser mon code ASP/HTML
    Par ahage4x4 dans le forum ASP
    Réponses: 7
    Dernier message: 30/05/2005, 10h29
  3. optimiser le code
    Par bibi2607 dans le forum ASP
    Réponses: 3
    Dernier message: 03/02/2005, 14h30
  4. syntaxe et optimisation de codes
    Par elitol dans le forum Langage SQL
    Réponses: 18
    Dernier message: 12/08/2004, 11h54
  5. optimisation du code et var globales
    Par tigrou2405 dans le forum ASP
    Réponses: 2
    Dernier message: 23/01/2004, 10h59

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