Fichier dont format date jour est sur 1 chiffre

cyrker Messages postés 6 Statut Membre -  
dubcek Messages postés 18627 Date d'inscription   Statut Contributeur Dernière intervention   -
Bonjour,
Sou Windows XP, avec McAfee 8.8, le fichier UpdateLog.txt (commande "set d" pour le chemin) utilise un format date bizarre :
les jours de 1 à 9 sont sur 1 seul caractère.
...et pas 01,02,03, ...,09 ...
les jours de 10 à 31 sont sur 2 caractères.
... et donc 10,11,12,13,...30,31...
---
Je voudrais via un script VBS ou DOS renommer la valeur jour de la date , provenant de la commande DOS "DATE /T"
---
Voici un début de script DOS, je sens que je vais faire une VBS intermédiaire...
----------------------------------------
::
:: VERIFICATION VERSION DAT
::
SET MCLOG=%DEFLOGDIR%\UpdateLog.txt
SET MCDATEJR=C:\nmsa\ocsagent\bin\Plugins\easyCstMod\TEMP\MCDATEJOUR.txt
SET MCDATEJRFR=C:\nmsa\ocsagent\bin\Plugins\easyCstMod\TEMP\MCDATEJOURFR.txt
set MCYEAR=c:\nmsa\ocsagent\bin\plugins\easyCstMod\TEMP\MCyear.txt
SET WAIT=c:\nmsa\ocsagent\bin\plugins\easyCstMod\sleep.exe
SET MCRESULT=c:\nmsa\ocsagent\bin\plugins\easyCstMod\TEMP\RESULTMCUPDATE.txt
SET MCOUT=c:\nmsa\ocsagent\bin\plugins\easyCstMod\MCAFEEUPDATE.out
SET MCSEARCH="Update succeeded to version"
SET MCSEARCHFR="jour du produit vers la version"
::
DEL %%MCLOG%
DEL %MCDATEJR%
DEL %MCDATEJRFR%
DEL %MCRESULT%
DEL %MCYEAR%
DEL %MCOUT%
::
DATE /T > %MCDATEJR%
%WAIT% 2
::
:: Pour Windows 2008
FOR /F "tokens=1,2,3 delims=/" %%a IN (%MCDATEJR%) DO (
ECHO %%cyear > %MCYEAR%
%WAIT% 2
FOR /F "tokens=1,2 eol= " %%p IN (%MCYEAR%) DO (
type "%MCLOG%" | FINDSTR %%p/%%b/%%a | FIND %MCSEARCH% > %MCRESULT%
)
)
::
:: Pour Windows XP Anglais et Français
:: Correction BUG McAfee Le jour de 01 à 09 est sur un seul chiffre !
DATE /T > %MCDATEJRFR%
%WAIT% 2
FOR /F "tokens=1,2,3 delims=/" %%t IN (%MCDATEJRFR%) DO (
ECHO %%t
IF %%t GEQ 10 (
ECHO "Jour Superieur ou egal a 10"
) ELSE (
ECHO "Jour inferieur a 10"
type "%MCLOG%" |FINDSTR %%u/%%t/%%v

)

)
::type "%MCLOG%" | FIND "%%u/%%t/%%v" | FIND %MCSEARCHFR%
::type "%MCLOG%" |FINDSTR %%u/%%t/%%v
::
::type "%MCLOG%" |FINDSTR %%u/%%t/%%v
::
:: |FIND "%%u/%%t/%%v"
:: >> "%MCRESULT%"
:: > "%MCRESULT%"
:: | FIND %MCSEARCH%
::
%WAIT% 2
FOR /F "tokens=1,2,3,4 delims= " %%e IN (%MCRESULT%) DO (
ECHO "%%e";"%%f";"%%g";"%%h" > %MCOUT%
)
----------------------------------------

5 réponses

  1. dubcek Messages postés 18627 Date d'inscription   Statut Contributeur Dernière intervention   5 660
     
    hello
    peux-tu montrer un exemple avant-après de ce qu'il faut renommer

    ps: la date retournée par date /t contient des / pas acceptés dans un nom de fichier
    0
  2. cyrker Messages postés 6 Statut Membre
     
    Il ne faut pas renommer un fichier.
    -
    C'est le contenu du fichier temporaire (format TXT) qu'il faut modifier.
    Le fichier concerné est :
    %DEFLOGDIR%\UpdateLog.txt
    ----
    et on peut étendre ce type de demande à d'autres commandes :

    DATE /T
    --> 09/10/2013

    wmic qfe get Description, HotFixID, InstalledOn | FIND "10/9/2013"
    -->
    Security Update KB2847311 10/9/2013
    Security Update KB2862330 10/9/2013
    Security Update KB2862335 10/9/2013
    Security Update KB2863240 10/9/2013
    Security Update KB2864058 10/9/2013
    Security Update KB2864202 10/9/2013
    Security Update KB2868038 10/9/2013
    Security Update KB2876284 10/9/2013
    Security Update KB2879017 10/9/2013
    Security Update KB2883150 10/9/2013
    Security Update KB2884256 10/9/2013
    ----
    -
    Ici, la valeur de la date contenue dans un fichier utilise ce format :
    Mois = 2 caractères (01 à 12)
    Jour = 1 caractère ( 01 à 09), puis 2 caractères (10 à 31)
    Année = 4 caractères (2013)
    -
    Donc, j'ai un problème avec le jour qui est soit avec un caractère, soit avec 2 caractères, dans le fichier temporaire.
    -
    Pour faire un FIND de la date (et remonter les lignes correspondantes), je dois donc, faire (au choix);
    #### 2 boucles dont :
    # l'une utilise la date avec jour sur 2 caractères
    # l'autre utilise la date avec jour sur 1 caractère
    ou
    #### modifier le fichier temporaire pour remettre la champ jour au bon format sur 2 caractères en ajoutant 1 zéro pour les valeurs de 1 à 9.
    A+
    0
  3. cyrker Messages postés 6 Statut Membre
     
    Bon,
    J'ai trouvé une solution :
    -
    WMIC Path Win32_LocalTime Get Day ,Month ,Year /Format:table
    ---->
    Day Month Year
    9 10 2013
    0
  4. dubcek Messages postés 18627 Date d'inscription   Statut Contributeur Dernière intervention   5 660
     
    la date courante avec 1 caractère pour les jours <= 9
    C:> type aa.bat
    @echo off
    set j=%date:~0,2%
    set m=%date:~3,2%
    set a=%date:~6,4%
    set j=1%j%
    set /a j=%j%-100
    echo %j%/%m%/%a%
    C:> aa
    9/10/2013

    C:>
    0
    1. cyrker Messages postés 6 Statut Membre
       
      Salut,
      -
      Pour :
      set j=%date:~0,2%
      -
      Est-il possible d'avoir une explication détaillée ?
      -
      Le script ci-dessous me permet de faire le job en utilisant uniquement les 2 commandes WMIC, sans utiliser DATE /T qui me posait problème.
      -
      Merci.
      0
    2. dubcek Messages postés 18627 Date d'inscription   Statut Contributeur Dernière intervention   5 660
       
      set j=%date:~0,2%
      on extrait 2 caractères à partir de la position 0, donc les 2 premiers.
      exxplication dans help set
      0
  5. Vous n’avez pas trouvé la réponse que vous recherchez ?

    Posez votre question
  6. cyrker Messages postés 6 Statut Membre
     
    SET WUPDCMD=wmic qfe get Description, HotFixID, InstalledOn /FORMAT:csv
    SET WUPDLOG=c:\nmsa\ocsagent\bin\plugins\easyCstMod\TEMP\WUPDATELIST.tmp
    SET WUPDLOG2=c:\nmsa\ocsagent\bin\plugins\easyCstMod\TEMP\WUPDATELIST2.tmp
    SET WUPDLOG3=c:\nmsa\ocsagent\bin\plugins\easyCstMod\TEMP\WUPDATELIST3.tmp
    SET WMICDATE=WMIC Path Win32_LocalTime Get Day ,Month ,Year /Format:csv
    SET DATELOG=c:\nmsa\ocsagent\bin\plugins\easyCstMod\TEMP\WMICDATE.tmp
    SET DATELOG2=c:\nmsa\ocsagent\bin\plugins\easyCstMod\TEMP\WMICDATE2.tmp
    SET DATELOG3=c:\nmsa\ocsagent\bin\plugins\easyCstMod\TEMP\WMICDATE3.tmp
    SET WINUPDATES3=c:\nmsa\ocsagent\bin\plugins\easyCstMod\WINUPDATES3.out
    ::
    DEL %WUPDLOG%
    DEL %WUPDLOG2%
    DEL %WINUPDATES3%
    ::
    %WUPDCMD% > %WUPDLOG%
    type %WUPDLOG% > %WUPDLOG2%
    ::
    %WMICDATE% > %DATELOG%
    type %DATELOG% > %DATELOG2%
    FOR /F "tokens=1,2,3,4 delims=," %%e IN (%DATELOG2%) DO (
    echo %%g/%%f/%%h > %DATELOG3%
    type %WUPDLOG2% | FIND "%%g/%%f/%%h" >> "%WUPDLOG3%"
    FOR /F "tokens=1,2,3,4 delims=," %%a IN (%WUPDLOG3%) DO (
    ECHO "%%b";"%%c";"%%d" >> "%WINUPDATES3%"
    )
    )
    0