标题: 【30元】压缩文件校验 [打印本页]
作者: bat小猎手 时间: 2022-1-9 19:57 标题: 【30元】压缩文件校验
一共含有四个文件夹。keep live。gooy fun
四个文件夹内文件格式为 .txt
数量上 live 和gooy 文件数量大于等于一小于等于15
live文件夹内必须要有 oner.txt
gooy内文件名dod.txt sds.txt
fun 内文件名vcv.txt xcd.txt
如果gooy fun 无文件不做压缩
最后使用7z进行压缩
作者: zaqmlp 时间: 2022-1-9 20:46
说明不清晰
是每个文件夹的条件都符合才全部打包到一起,还是每个文件夹的条件只要符合各自条件则分别将自身打包成一个,或者是其他要求??
作者: flashercs 时间: 2022-1-9 20:46
- @echo off
- cd /d "%~dp0"
- set z7="C:\Program Files\7-Zip\7z.exe"
- set archive="压缩包.7z"
- set folders=keep\ live\ gooy\ fun\
- for %%A in (%folders%) do (
- if not exist "%%A" (
- echo 文件夹 "%%A" 不存在
- pause
- exit /b
- )
- )
-
- set ctr=0
- for %%A in ("live\*.txt") do (
- set /a ctr+=1
- )
- if %ctr% lss 1 echo 文件夹 live 文件数量小于1 & pause & exit /b
- if %ctr% gtr 15 echo 文件夹 live 文件数量大于15 & pause & exit /b
- set ctr=0
- for %%A in ("gooy\*.txt") do (
- set /a ctr+=1
- )
- if %ctr% lss 1 echo 文件夹 gooy 文件数量小于1 & pause & exit /b
- if %ctr% gtr 15 echo 文件夹 gooy 文件数量大于15 & pause & exit /b
-
- for %%A in ("live\oner.txt" "gooy\dod.txt" "gooy\sds.txt" "fun\vcv.txt" "fun\xcd.txt") do (
- if not exist %%A echo %%A 不存在. & pause & exit /b
- )
- set ctr=0
- for %%A in ("fun\*.txt") do (
- set /a ctr+=1
- )
- if %ctr% equ 0 echo 文件夹 fun 文件数量小于1 & pause & exit /b
-
- %z7% a %archive% %folders%
-
- pause
- exit /b
复制代码
作者: zaqmlp 时间: 2022-1-9 20:51
- @echo off&cd /d "%~dp0"
- set "exefile=D:\Program Files\Toolbox\7-Zip\7z.exe"
- set folder="keep" "live" "gooy" "fun"
-
- if not exist "%exefile%" (echo;"%exefile%" no found&pause&exit)
- set "f="
-
- for %%a in (%folder%) do (
- set n=0
- for /f "delims=" %%b in ('dir /a-d/b "%%~a\" 2^>nul') do (
- if /i "%%~xb" neq ".txt" (
- set f=1
- ) else (
- set /a n+=1
- )
- )
- if /i "%%~a" equ "live" (
- setlocal enabledelayedexpansion
- if !n! equ 0 set f=1
- if !n! gtr 15 set f=1
- endlocal
- )
- if /i "%%~a" equ "gooy" (
- setlocal enabledelayedexpansion
- if !n! equ 0 set f=1
- if !n! gtr 15 set f=1
- endlocal
- )
- )
-
- if not exist "live\oner.txt" set f=1
-
- for %%a in (
- "dod.txt"
- "sds.txt"
- ) do (if not exist "gooy\%%~a" set f=1)
-
- for %%a in (
- "vcv.txt"
- "xcd.txt"
- ) do (if not exist "fun\%%~a" set f=1)
-
-
- if not defined f (
- "%exefile%" a -y "out.7z" %folder%
- )
- pause
- exit
复制代码
作者: Batcher 时间: 2022-1-9 20:57
回复 1# bat小猎手 - @echo off
- cd /d "%~dp0"
- set "ExecFlag=1"
-
- if exist "C:\Program Files\7-Zip\7z.exe" (
- set "My7z=C:\Program Files\7-Zip\7z.exe"
- ) else if exist "C:\Program Files (x86)\7-Zip\7z.exe" (
- set "My7z=C:\Program Files (x86)\7-Zip\7z.exe"
- ) else (
- echo 找不到 7z.exe
- goto :End
- )
- echo %My7z%
-
- REM 后缀名检查
- for %%i in (keep live gooy fun) do (
- for /f "delims=" %%j in ('dir /b /a-d "%%i" 2^>nul') do (
- if /i "%%~xj" neq ".txt" (
- echo 存在后缀名不为txt的文件 %%i\%%j
- set "ExecFlag=0"
- )
- )
- )
-
- REM 文件夹下面的文件数量检查
- set "FileMin=1"
- set "FileMax=15"
- set "FileCount=0"
- for /f "delims=" %%i in ('dir /b /a-d live\*.* 2^>nul') do (
- set /a FileCount+=1
- )
- if %FileCount% lss %FileMin% (
- echo live 文件夹下面的文件[%FileCount%个]少于[%FileMin%个]
- set "ExecFlag=0"
- ) else if %FileCount% gtr %FileMax% (
- echo live 文件夹下面的文件[%FileCount%个]多于[%FileMax%个]
- set "ExecFlag=0"
- )
- set "FileCount=0"
- for /f "delims=" %%i in ('dir /b /a-d gooy\*.* 2^>nul') do (
- set /a FileCount+=1
- )
- if %FileCount% lss %FileMin% (
- echo gooy 文件夹下面的文件[%FileCount%个]少于[%FileMin%个]
- set "ExecFlag=0"
- ) else if %FileCount% gtr %FileMax% (
- echo gooy 文件夹下面的文件[%FileCount%个]多于[%FileMax%个]
- set "ExecFlag=0"
- )
-
- REM 特定文件名检查
- for %%i in (dod.txt sds.txt) do (
- if not exist "gooy\%%i" (
- echo 缺少文件 gooy\%%i
- set "ExecFlag=0"
- )
- )
- for %%i in (vcv.txt xcd.txt) do (
- if not exist "fun\%%i" (
- echo 缺少文件 fun\%%i
- set "ExecFlag=0"
- )
- )
-
- echo 压缩条件 %ExecFlag%
- if %ExecFlag% equ 1 (
- "%My7z%" a keep.zip .\keep\
- "%My7z%" a live.zip .\live\
- "%My7z%" a gooy.zip .\gooy\
- "%My7z%" a fun.zip .\fun\
- ) else (
- goto :End
- )
-
- :End
- pause
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |