CSS
特定のディレクトリにファイルをコピーするバッチ スクリプトを作成しましたが、コピー先ディレクトリでファイルを開くと感嘆符が削除されるCSS
という問題があります。
元の CSS には、次のような感嘆符付きのスタイルが含まれています。
.foo
{
color: pink !important;
}
私のCSSの結果は
.foo
{
color: pink important;
}
私はこれの根本的な原因を調べ、以下に基づいて調べました:感嘆符がバッチファイルで常に削除されている
しかし、私の場合、遅延拡張を無効にする必要がある場所がわかりません。
参考までに、私のバッチは次のことを行っています:
コンマで区切られたテーマ文字列ごとに、特定の文字列に一致する行番号の開始番号と終了番号を見つけます。
今、私は開始と終了の行番号を持っています (例 500 と 1000)
500行目と1000行目の間を除いてファイルの内容をコピーします
ファイナライズされたファイルが宛先ディレクトリにコピーされます
さらに明確にする必要がある場合はお知らせください。事前に感謝します。
バッチ (スニペット):
set themes=Platinum,Granite,Sun,Sky,Burgundy,Leaf,Twilight,Sharepoint 2010,Sharepoint 2013
rem Directory that contains theme css files
set RUNTIME_DEST=%K2DIR%\K2 SmartForms Runtime\Styles\Themes
REM Do something with each substring
call :parse "%themes%"
goto :eof
:parse
setlocal
for %%a in ("%themes:,=" "%") do (
call :getLineNumber %%a
)
endlocal
goto :eof
:getLineNumber
setlocal
echo file name is %~1
set filename=%~1
rem Get start and end line numbers of the unwanted section
for /F "delims=:" %%a in ('findstr /N /C:"PickerCollectionThemeStart" "%RUNTIME_DEST%\%filename%.css"') do (
set start=%%a
)
for /F "delims=:" %%a in ('findstr /N /C:"PickerCollectionThemeEnd" "%RUNTIME_DEST%\%filename%.css"') do (
set end=%%a
)
if not defined start (
echo start not defined...
set start=0
set end=0
)
echo start val = !start!
echo end val = !end!
call :resetTheme "%filename%" "%start%" "%end%"
endlocal
goto :eof
:resetTheme
setlocal
set filename=%~1
set start=%~2
set end=%~3
echo %fileName%
echo %start%
echo %end%
echo ---------------
rem Create a copy file to modify
xcopy "%RUNTIME_DEST%\%filename%.css" "%cd%\Batch_tmp" /y /z /r
echo creating tmp copy...
rem Rename the file so we can modify and create finalized version
ren "Batch_tmp\%fileName%.css" "%fileName%_tmp.css"
echo coping all line except section...
rem Copy all lines, except the ones in start-end section
(for /F "tokens=1* delims=:" %%a in ('findstr /N "^" "Batch_tmp\%fileName%_tmp.css"') do (
if %%a lss %start% echo(%%b
if %%a gtr %end% echo(%%b
)) > Batch_tmp\!fileName!.css
echo copying to blackpearl dir
rem Finally move the css over to blackpearl directory
setlocal DisableDelayedExpansion
xcopy "Batch_tmp\%fileName%.css" "%RUNTIME_DEST%" /y /z /r
endlocal
endlocal
goto :eof
:eof
pause
アップデート
以下は、アドバイスに基づいて機能する私のソリューションです。違いは、指示に従って、スクリプトの先頭で EnableDelayedExpansion を設定してバッチ スコープ全体に影響を与え、DisableDelayedExpansion を適用する場所にのみ設定することです。
set themes=Platinum,Granite,Sun,Sky,Burgundy,Leaf,Twilight,Sharepoint 2010,Sharepoint 2013
rem Directory that contains theme css files
set RUNTIME_DEST=%K2DIR%\K2 SmartForms Runtime\Styles\Themes
REM Do something with each substring
call :parse "%themes%"
goto :eof
:parse
setlocal
for %%a in ("%themes:,=" "%") do (
echo ------------------------
call :getLineNumber %%a
)
endlocal
goto :eof
:getLineNumber
setlocal
echo file name is %~1
set filename=%~1
rem Get start and end line numbers of the unwanted section
for /F "delims=:" %%a in ('findstr /N /C:"PickerCollectionThemeStart" "%RUNTIME_DEST%\%filename%.css"') do (
set start=%%a
)
for /F "delims=:" %%a in ('findstr /N /C:"PickerCollectionThemeEnd" "%RUNTIME_DEST%\%filename%.css"') do (
set end=%%a
)
if not defined start (
echo start not defined...
set start=0
set end=0
)
echo start val = !start!
echo end val = !end!
call :resetTheme "%filename%" "%start%" "%end%"
endlocal
goto :eof
:resetTheme
setlocal
set filename=%~1
set start=%~2
set end=%~3
echo %fileName%
echo %start%
echo %end%
rem Create a copy file to modify
xcopy "%RUNTIME_DEST%\%filename%.css" "%cd%\Batch_tmp" /y /z /r
echo creating tmp copy...
rem Rename the file so we can modify and create finalized version
ren "Batch_tmp\%fileName%.css" "%fileName%_tmp.css"
echo coping all line except section...
rem Copy all lines, except the ones in start-end section
(for /F "tokens=1* delims=:" %%a in ('findstr /N "^" "Batch_tmp\%fileName%_tmp.css"') do (
setlocal DisableDelayedExpansion
if %%a lss %start% echo(%%b
if %%a gtr %end% echo(%%b
endlocal
)) > Batch_tmp\!fileName!.css
echo copying to blackpearl dir
rem Finally move the css over to blackpearl directory
xcopy "Batch_tmp\%fileName%.css" "%RUNTIME_DEST%" /y /z /r
endlocal
goto :eof
:eof