Erreur dans l'exécution d'un script de récupération de données de fichiers
Bonjour à tous,
Je crée ce sujet car une connaissance m'a créé un script en batch dont le but est de catégoriser des types de fichier dans une série de dossiers, d'après leur taille (x*y). Il m'a fait une première version dont l'affichage des résultats dans le .txt est parfaite pour l'intégrer directement à mon fichier excel, mais a fait des modifications pour le rendre plus précis dans sa catégorisation (d'après leur taille x*y justement, en utilisant exiftool). Mais il n'a pas remis cet affichage final de la première version qui rendait sous forme de phrases les résultats, et malheureusement il doit être occupé et ne me répond plus. J'ai essayé de modifier le script moi-même mais vraiment je n'y connais pas grand chose donc le programme se lance sans résultat. Je vous mets ici le code où j'ai tenté d'intégrer la mise en page de la première version dans la deuxième version.
J'espère que mon propos est suffisamment clair, je ne souhaitais pas vous noyer sous les détails, mais n'hésitez pas à me signaler toute précision nécessaire. En vous remerciant par avance.
Code:
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 163 164 165 166 167 168
| @echo off
cd %~p0
del error.txt
dir /a:d /b > list.txt
FOR %%A IN (list.txt) DO set size=%%~zA
IF "%size%"==0"" (
ECHO Aucun dossier trouver.
pause>nul
exit
)
echo Resultat : >a.txt
echo.>>a.txt
set a7=0
set a5=0
set a6=0
set a4=0
set fichea4=fiches
set fichea5=fiches
set fichea6=fiches
set fichea7=fiches
echo stop>>list.txt
for /f "tokens=2 delims=:" %%a in ('find /c /v "" list.txt') do set /a Lines=%%a
set /A Lines=%Lines%-1
echo Dossier trouver.
echo Nombre de dossier : %Lines%
echo Nom des dossier :
set li=0
set li2=0
:retour
more +%li% list.txt>list2.txt
set /p string2=< list2.txt
set string3=%string2: =%
set /A li=%li%+1
if "%string3%"=="stop" (
goto all
)
echo %string3%
dir /s /b %string3%\*.jpg >temp.txt
FOR %%A IN (temp.txt) DO set size=%%~zA
echo stop>>temp.txt
echo Fichier en cours :
:retour2
more +%li2% temp.txt>temp2.txt
set /p string4=< temp2.txt
set string5=%string4: =%
set /A li2=%li2%+1
if "%string5%"=="stop" (
set li2=0
echo Dossier : %string3% >> R.txt
if "%a4%"=="0" (goto a4skip)
if "%a4%"=="1" (set fichea4=fiche)
set "a=%a4% %fichea4% papier A4"
:a4skip
if "%a5%"=="0" (goto a5skip)
if "%a5%"=="1" (set fichea5=fiche)
if "%a6%"=="0" (set "a=%a% et %a5% %fichea5% papier A5" & goto a5skip)
if "%a4%"=="0" (set "a=%a5% %fichea5% papier A5" & goto a5skip)
if NOT "%a5%"=="0" (set "a=%a%, %a5% %fichea5% papier A5")
:a5skip
if "%a6%"=="0" (goto a6skip)
if "%a6%"=="1" (set fichea6=fiche)
if "%a5%"=="0" (set "a=%a6% %fichea6% papier A6")
if "%a7%"=="0" (set "a=%a% et %a6% %fichea6% papier A6" & goto a6skip)
if NOT "%a6%"=="0" (set "a=%a%, %a6% %fichea6% papier A6")
:a6skip
if "%a7%"=="0" (goto a7skip)
if "%a7%"=="1" (set fichea7=fiche)
if "%a6%"=="0" (set "a=%a7% %fichea7% papier A7")
if NOT "%a7%"=="0" (set "a=%a% et %a7% %fichea7% papier A7")
:a7skip
echo. >>R.txt
set a7=0
set a5=0
set a6=0
set a4=0
goto retour
)
) else (
set "filename=%string5%"
For %%A in ("%filename%") do (
set i=%%~nxA
)
set lef=%string3%\%i%
echo %lef%
echo %string5% | seed "s/ //g" > tiph.txt
set /p string7=<tiph.txt
exiftool -ImageSize %lef% | seed "s/Image Size : //g" > temp3.txt
set /p string=<temp3.txt
for /f "tokens=1 delims=x" %%a in ("%string%") do (
set x=%%a
)
set "y=%string:x=" & set "y=%"
if %x% GEQ 1200 (
if %x% LEQ 1600 (
if %y% GEQ 900 (
if %y% LEQ 1330 (
echo +1 A6
set /a a6="%a6%+1"
goto retour2
)
)
)
)
if %x% GEQ 1400 (
if %x% LEQ 1700 (
if %y% GEQ 2000 (
if %y% LEQ 2500 (
echo +1 A5
set /a a5="%a5%+1"
goto retour2
)
)
)
)
if %x% GEQ 2400 (
if %x% LEQ 2600 (
if %y% GEQ 2900 (
if %y% LEQ 3200 (
echo +1 A4
set /a a4="%a4%+1"
goto retour2
)
)
)
)
echo Error.
echo Problem with file : "%string5%">> error.txt
goto retour2
pause>nul
:all
timeout /t 2 >NUL
if exist "error.txt" start error.txt
start R.txt
del Final.txt
del list.txt
del list2.txt
del temp.txt
del temp2.txt |
Je vous mets également pour comparer la première version du script (bon affichage dans le .txt, mais méthode utilisant le poids des fichiers), puis la seconde version (mauvais affichage, mais bonne méthode en x*y).
VERSION 1
Code:
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
| @echo off
cd %~p0
dir /a:d /b > list.txt
FOR %%A IN (list.txt) DO set size=%%~zA
IF "%size%"==0"" (
ECHO Aucun dossier trouver.
pause>nul
exit
)
echo Resultat : >a.txt
echo. >>a.txt
set a7=0
set a5=0
set a6=0
set a4=0
set fichea4=fiches
set fichea5=fiches
set fichea6=fiches
set fichea7=fiches
echo stop>>list.txt
for /f "tokens=2 delims=:" %%a in ('find /c /v "" list.txt') do set /a Lines=%%a
set /A Lines=%Lines%-1
echo Dossier trouver.
echo Nombre de dossier : %Lines%
echo Nom des dossier :
set li=0
set li2=0
:retour
more +%li% list.txt>list2.txt
set /p string2=< list2.txt
set string3=%string2: =%
set /A li=%li%+1
if "%string3%"=="stop" (
goto all
)
dir /s /b %string3%\*.jpg >temp.txt
echo stop>>temp.txt
:retour2
more +%li2% temp.txt>temp2.txt
set /p string4=< temp2.txt
set string5=%string4: =%
set /a li2=%li2%+1
if "%string5%"=="stop" (goto oo)
goto else
:oo
set li2=0
echo Dossier : %string3% >> R.txt
if "%a4%"=="0" (goto a4skip)
if "%a4%"=="1" (set fichea4=fiche)
set "a=%a4% %fichea4% papier A4"
:a4skip
if "%a5%"=="0" (goto a5skip)
if "%a5%"=="1" (set fichea5=fiche)
if "%a6%"=="0" (set "a=%a% et %a5% %fichea5% papier A5" & goto a5skip)
if "%a4%"=="0" (set "a=%a5% %fichea5% papier A5" & goto a5skip)
if NOT "%a5%"=="0" (set "a=%a%, %a5% %fichea5% papier A5")
:a5skip
if "%a6%"=="0" (goto a6skip)
if "%a6%"=="1" (set fichea6=fiche)
if "%a5%"=="0" (set "a=%a6% %fichea6% papier A6")
if "%a7%"=="0" (set "a=%a% et %a6% %fichea6% papier A6" & goto a6skip)
if NOT "%a6%"=="0" (set "a=%a%, %a6% %fichea6% papier A6")
:a6skip
if "%a7%"=="0" (goto a7skip)
if "%a7%"=="1" (set fichea7=fiche)
if "%a6%"=="0" (set "a=%a7% %fichea7% papier A7")
if NOT "%a7%"=="0" (set "a=%a% et %a7% %fichea7% papier A7")
:a7skip
echo %a%>>R.txt
echo. >>R.txt
set a7=0
set a5=0
set a6=0
set a4=0
goto retour
:else
echo %string5%
FOR %%A IN (%string5%) DO set size5=%%~zA
set /a size5="%size5%/1000"
if %size5% LEQ 300 (
set /a a7="%a7%+1"
goto retour2
)
if %size5% LEQ 600 (
set /a a6="%a6%+1"
goto retour2
)
if %size5% LEQ 1200 (
set /a a5="%a5%+1"
goto retour2
)
if %size5% GEQ 1200 (
set /a a4="%a4%+1"
goto retour2
)
echo Possible error contact riyad.
pause>Nul
:all
timeout /t 2 >NUL
echo Fini
start R.txt
del Final.txt
del list.txt
del list2.txt
del temp.txt
del temp2.txt |
VERSION 2
Code:
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
| @echo off
cd %~p0
del error.txt
dir /a:d /b > list.txt
FOR %%A IN (list.txt) DO set size=%%~zA
IF "%size%"==0"" (
ECHO Aucun dossier trouver.
pause>nul
exit
)
echo Resultat : >a.txt
echo.>>a.txt
set a7=0
set a5=0
set a6=0
set a4=0
echo stop>>list.txt
for /f "tokens=2 delims=:" %%a in ('find /c /v "" list.txt') do set /a Lines=%%a
set /A Lines=%Lines%-1
echo Dossier trouver.
echo Nombre de dossier : %Lines%
echo Nom des dossier :
set li=0
set li2=0
:retour
more +%li% list.txt>list2.txt
set /p string2=< list2.txt
set string3=%string2: =%
set /A li=%li%+1
if "%string3%"=="stop" (
goto all
)
echo %string3%
dir /s /b %string3%\*.jpg >temp.txt
FOR %%A IN (temp.txt) DO set size=%%~zA
echo stop>>temp.txt
echo Fichier en cours :
:retour2
more +%li2% temp.txt>temp2.txt
set /p string4=< temp2.txt
set string5=%string4: =%
set /A li2=%li2%+1
if "%string5%"=="stop" (
set li2=0
echo Dossier : %string3% >> a.txt
echo A4 = %a4% >> a.txt
echo A5 = %a5% >> a.txt
echo A6 = %a6% >> a.txt
echo A7 = %a7% >> a.txt
echo. >>a.txt
set a7=0
set a5=0
set a6=0
set a4=0
goto retour
)
) else (
set "filename=%string5%"
For %%A in ("%filename%") do (
set i=%%~nxA
)
set lef=%string3%\%i%
echo %lef%
echo %string5% | seed "s/ //g" > tiph.txt
set /p string7=<tiph.txt
exiftool -ImageSize %lef% | seed "s/Image Size : //g" > temp3.txt
set /p string=<temp3.txt
for /f "tokens=1 delims=x" %%a in ("%string%") do (
set x=%%a
)
set "y=%string:x=" & set "y=%"
if %x% GEQ 1200 (
if %x% LEQ 1600 (
if %y% GEQ 900 (
if %y% LEQ 1330 (
echo +1 A6
set /a a6="%a6%+1"
goto retour2
)
)
)
)
if %x% GEQ 1400 (
if %x% LEQ 1700 (
if %y% GEQ 2000 (
if %y% LEQ 2500 (
echo +1 A5
set /a a5="%a5%+1"
goto retour2
)
)
)
)
if %x% GEQ 2400 (
if %x% LEQ 2600 (
if %y% GEQ 2900 (
if %y% LEQ 3200 (
echo +1 A4
set /a a4="%a4%+1"
goto retour2
)
)
)
)
echo Error.
echo Problem with file : "%string5%">> error.txt
goto retour2
pause>nul
:all
timeout /t 2 >NUL
if exist "error.txt" start error.txt
start a.txt
del Final.txt
del list.txt
del list2.txt
del temp.txt
del temp2.txt |