我有一个脚本,在制作网站的生产版本之前使用YUICompressor压缩所有CSS和JS。我得到了它的工作,但我想通过压缩那些被修改的文件加快速度。
换句话说,如果输出文件比输入文件新,则应该跳过。
@echo off
set batch_path=%~p0
setlocal enabledelayedexpansion
call:compress css styles\core\ ..\core\resources\styles\
call:compress js scripts\core\ ..\core\resources\scripts\
pause
goto:eof
:compress
for /r .\%~2 %%f in (*) do (
set filename=%%f
rem set output filename to correct directory and add .min before extension
set output_filename=%%~pf
set output_filename=!output_filename:%batch_path%%~2=!
set output_filename=%~3!output_filename!%%~nf.min%%~xf
echo. !filename! =^> !output_filename!
rem --- check file modify times ---
rem change \ into \\ for yuicompressor
set filename=!filename:\=\\!
set output_filename=!output_filename:\=\\!
java -jar yuicompressor-2.4.8.jar --type %~1 -o "!output_filename!" "!filename!"
)
goto:eof
我只找到复杂的解决方案,我如何比较文件修改时间并继续或跳过?
答案 0 :(得分:3)
请参阅Comparing a modified file date with the current date in a batch file
for %%f in (%filename%) do set filedt=%%~tf
for %%f in (!output_filename!) do set outfiledt=%%~tf
if %filedt:~0, 10% LSS %outfiledt:~0, 10% DO SOMETHING
如果filename早于outfilename - 做点什么。