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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
| @ECHO OFF
CHCP 850>NUL
CLS
SETLOCAL EnableDelayedExpansion
REM -------------------------------------------------------------------------------------------------------------
REM *** Traitement info date de copie ***
REM Calcul du nombre de jours en fonction du mois de l'année
SET /A JA=31
SET /A FE=%JA%+29
SET /A MA=%JA%+%FE%+31
SET /A AV=%JA%+%FE%+%MA%+30
SET /A MAI=%JA%+%FE%+%MA%+%AV%+31
SET /A JUIN=%JA%+%FE%+%MA%+%AV%+%MAI%+30
SET /A JU=%JA%+%FE%+%MA%+%AV%+%MAI%+%JUIN%+31
SET /A AO=%JA%+%FE%+%MA%+%AV%+%MAI%+%JUIN%+%JU%+31
SET /A SE=%JA%+%FE%+%MA%+%AV%+%MAI%+%JUIN%+%JU%+%AO%+30
SET /A OC=%JA%+%FE%+%MA%+%AV%+%MAI%+%JUIN%+%JU%+%AO%+%SE%+31
SET /A NO=%JA%+%FE%+%MA%+%AV%+%MAI%+%JUIN%+%JU%+%AO%+%SE%+%OC%+30
SET J1=%date:~0,2%
SET M1=%date:~3,2%
SET A1=%date:~6,4%
SET DA=%A1%-%M1%-%J1%
SET DAbis=%date%
SET /A J1=%date:~0,2%
SET /A M1=%date:~3,2%
SET /A A1=%date:~6,4%
SET MemoErreurDate=OK
REM 1er test date
IF NOT EXIST Backup_date.txt (
Set MemoErreurDate=Absence de fichier Backup_date.txt : une nouvelle copie va etre generee.
SET OldDate=2000/01/01
GOTO LOOP1
)
SET OldDate=2000/01/01
FOR /f "delims=" %%i IN ('TYPE Backup_date.txt') DO SET OldDate=%%i
SET /A J2=%OldDate:~8,2%
SET /A M2=%OldDate:~5,2%
SET /A A2=%OldDate:~0,4%
REM 2ème test date
SET /A Test2=0
IF "%A2%" EQU "" SET /A Test2=1
IF "%M2%" EQU "" SET /A Test2=1
IF "%J2%" EQU "" SET /A Test2=1
IF %Test2% EQU 1 (
SET MemoErreurDate=Date [%OldDate%] de la copie precedente inexploitable : une nouvelle copie va etre generee.
SET OldDate=2000/01/01
GOTO LOOP1
)
IF %A2% EQU 0 SET /A Test2=1
IF %M2% EQU 0 SET /A Test2=1
IF %J2% EQU 0 SET /A Test2=1
IF %Test2% EQU 1 (
SET MemoErreurDate=Date [%OldDate%] de la copie precedente inexploitable : une nouvelle copie va etre generee.
SET OldDate=2000/01/01
GOTO LOOP1
)
REM 3ème test date - Contenu fichier vide
IF "%OldDate%" EQU "2000/01/01" (
SET MemoErreurDate=Contenu du fichier Backup_date.txt vide : une nouvelle copie va etre generee.
GOTO LOOP1
)
SET /A J2=%OldDate:~8,2%
IF %J2:~0,1% EQU 0 SET /A J2=%J2:~1,1%
SET /A J2=%J2%
SET /A M2=%OldDate:~5,2%
IF %M2:~0,1% EQU 0 SET /A M2=%M2:~1,1%
SET /A M2=%M2%
SET /A A2=%OldDate:~0,4%
IF %M1% EQU 1 SET /A NBJ1=0
IF %M1% EQU 2 SET /A NBJ1=%JA%
IF %M1% EQU 3 SET /A NBJ1=%FE%
IF %M1% EQU 4 SET /A NBJ1=%MA%
IF %M1% EQU 5 SET /A NBJ1=%AV%
IF %M1% EQU 6 SET /A NBJ1=%MAI%
IF %M1% EQU 7 SET /A NBJ1=%JUIN%
IF %M1% EQU 8 SET /A NBJ1=%JU%
IF %M1% EQU 9 SET /A NBJ1=%AO%
IF %M1% EQU 10 SET /A NBJ1=%SE%
IF %M1% EQU 11 SET /A NBJ1=%OC%
IF %M1% EQU 12 SET /A NBJ1=%NO%
IF %M2% EQU 1 SET /A NBJ2=0
IF %M2% EQU 2 SET /A NBJ2=%JA%
IF %M2% EQU 3 SET /A NBJ2=%FE%
IF %M2% EQU 4 SET /A NBJ2=%MA%
IF %M2% EQU 5 SET /A NBJ2=%AV%
IF %M2% EQU 6 SET /A NBJ2=%MAI%
IF %M2% EQU 7 SET /A NBJ2=%JUIN%
IF %M2% EQU 8 SET /A NBJ2=%JU%
IF %M2% EQU 9 SET /A NBJ2=%AO%
IF %M2% EQU 10 SET /A NBJ2=%SE%
IF %M2% EQU 11 SET /A NBJ2=%OC%
IF %M2% EQU 12 SET /A NBJ2=%NO%
SET /A DiffDate=(%A1%-%A2%)*365+(%NBJ1%-%NBJ2%)+(%J1%-%J2%)
REM 4ème test date
SET /A A3=%A1%+1
SET Test4=VIDE
IF %A2% LSS 2016 SET Test4=Annee
IF %A2% GTR %A3% SET Test4=Annee
IF %M2% LSS 1 SET Test4=Mois
IF %M2% GTR 12 SET Test4=Mois
IF %J2% LSS 1 SET Test4=Jour
IF %J2% GTR 31 SET Test4=Jour
IF "%Test4%" NEQ "VIDE" (
SET MemoErreurDate=%Test4% de la date [%OldDate%] de copie precedente inexploitable : une nouvelle copie va etre generee.
SET OldDate=2000/01/01
GOTO LOOP1
)
REM 5ème test date
IF %DiffDate% LSS 0 (
SET MemoErreurDate=Date [%OldDate%] de la copie precedente incoherente : une nouvelle copie va etre generee.
SET OldDate=2000/01/01
GOTO LOOP1
)
REM 6ème test date
IF %DiffDate% LSS 7 (
ECHO.
ECHO Precedente copie realisee il y a moins d'une semaine : pas de une nouvelle a generer.
SET /A $AbsRep2=1
GOTO SORTIE_PROGRAMME
)
ECHO.
ECHO Precedente copie realisee il y a %DiffDate% jours : une nouvelle va etre generee.
REM -------------------------------------------------------------------------------------------------------------
REM *** Cas de l'absence d'info concernant la date de la copie précédente ***
:LOOP1
IF "%MemoErreurDate%" NEQ "OK" (
ECHO.
ECHO %MemoErreurDate%
)
REM -------------------------------------------------------------------------------------------------------------
REM *** Ecrire la date de la copie dans un fichier sauvegarde ***
ECHO.
ECHO Ecriture de la date de la copie dans le fichier Backup_date.txt
ECHO %DA%> Backup_date.txt
:SORTIE_PROGRAMME
PAUSE |
Partager