Aide Fichier Batch

Résolu
RAD ZONE Messages postés 5362 Statut Contributeur -  
RAD ZONE Messages postés 5362 Statut Contributeur -
Bonjour,

Ne connaissant pas pas Widaub 10 je voudrai juste savoir si ces commande sont valables pour W10

ver | find /i "version 10" > nul
if %errorlevel%==0 goto vwin=Windows 10
ver | find /i "version 10.0.10586" > nul
if %errorlevel%==0 goto vwin=Windows 10
ver | find /i "version 10.0.10240" > nul
if %errorlevel%==0 goto vwin=Windows 10
ver | find /i "version 10.0.9926" > nul
if %errorlevel%==0 goto vwin=Windows 10
ver | find /i "version 6.4.9879" > nul
if %errorlevel%==0 goto vwin=Windows 10
ver | find /i "version 6.4.9860" > nul
if %errorlevel%==0 goto vwin=Windows 10
ver | find /i "version 6.4.9841" > nul
if %errorlevel%==0 goto vwin=Windows 10
ver | find /i "version 6.3.9600" > nul
if %errorlevel%==0 goto vwin=Windows 8
ver | find /i "version 6.2." > nul
if %errorlevel%==0 goto vwin=Windows 8
ver | find /i "version 6.1." > nul
if %errorlevel%==0 goto winseven
ver | find /i "version 6.0." > nul
if %errorlevel%==0 goto winseven
ver | find /i "version 5.1." > nul
if %errorlevel%==0 goto winxp
Windows 10
if exist %USERPROFILE%\Bureau\nul (
set Destination="%USERPROFILE%\Bureau\Audit.txt"
) else (set Destination="%USERPROFILE%\Desktop\Audit.txt")
dir/ad/d/o/b "%USERPROFILE%\AppData\Local\un dossier" >"%USERPROFILE%\Desktop\Audit.txt"
goto end
Windows 8
if exist %USERPROFILE%\Bureau\nul (
set Destination="%USERPROFILE%\Bureau\Audit.txt"
) else (set Destination="%USERPROFILE%\Desktop\Audittxt")
dir/ad/d/o/b "%USERPROFILE%\AppData\Local\un dossier" >"%USERPROFILE%\Desktop\Audit.txt"
goto end
:winseven
if exist %USERPROFILE%\Bureau\nul (
set Destination="%USERPROFILE%\Bureau\Audit.txt"
) else (set Destination="%USERPROFILE%\Desktop\Audit.txt")
dir/ad/d/o/b "%USERPROFILE%\AppData\Local\un dossier" >"%USERPROFILE%\Desktop\Audit.txt"
goto end
:winxp
if exist %USERPROFILE%\Bureau\nul (
set Destination="%USERPROFILE%\Bureau\Audit.txt"
) else (set Destination="%USERPROFILE%\Desktop\Audit.txt")
dir/ad/d/o/b "%USERPROFILE%\Local Settings\Application Data\un dossier
" >%Destination%
goto end
:end



il y a longtemp que je n ai pas ecrit un fichier batch !! il y a peut etre plus simple :-)

merci



--

♣  La plus grande erreur que puisse faire un homme est d'avoir peur d'en faire une. ♣

1 réponse

  1. barnabe0057 Messages postés 14329 Date d'inscription   Statut Contributeur Dernière intervention   4 930
     
    Bonjour,

    Effectivement il y a trop de répétitions dans ton code, voilà plus simple :

    @echo off

    set destination=%USERPROFILE%\Desktop\Audit.txt
    set dossier1=%USERPROFILE%\AppData\Local\un dossier
    set dossier2=%USERPROFILE%\Local Settings\Application Data\un dossier

    ver | findstr /i "10. 6.4." >nul && call :fonction "%destination%" "%dossier1%"

    ver | findstr /i "6.3. 6.2." >nul && call :fonction "%destination%" "%dossier1%"

    ver | findstr /i "6.1. 6.0." >nul && call :fonction "%destination%" "%dossier1%"

    ver | findstr /i "5.1." >nul && call :fonction "%destination%" "%dossier2%"

    exit

    :fonction
    dir /ad /d /b "%~2" > "%~1"
    goto :eof

    rem

    Ces commandes sont tout à fait valables pour windows 10.

    0
    1. RAD ZONE Messages postés 5362 Statut Contributeur 1 360
       
      Salut

      Merci de cette GRANDE simplification :-)

      plus je tapais plus je me disais qu il devait y avoir plus simple , mais j etais parti sur ma lancee :-)

      merci
      A+
      0