本帖最后由 kingshui 于 2013-4-24 19:42 编辑
有一test1文件包含以下内容(文件名及路径)- X:\require\https%3A%2F%2Fgithub.com
- X:\require\!test.com
复制代码 想要输出成如下(test2)的内容:- "X:\require\https%3A%2F%2Fgithub.com" "\https%3A%2F%2Fgithub.com"
- "X:\require\!test.com" "\!test.com"
复制代码 已经作出如下代码:- For /f "delims=" %%i In (test1) Do (
- Echo "%%i" "%~nxi">>test2
- )
复制代码 想了一些法子,都无法同时支持!和%的输出...
望指点,变量延迟用怕了.
这是完整一点的- :package
- if "%~1" NEQ "" (
- echo %~1 >>patch
- if "%~2" NEQ "" echo %~2 >>patch
- if "%~3" NEQ "" echo %~3 >>patch
- if "%~4" NEQ "" echo %~4 >>patch
- if "%~5" NEQ "" echo %~5 >>patch
- if "%~6" NEQ "" echo %~6 >>patch
- if "%~7" NEQ "" echo %~7 >>patch
- if "%~8" NEQ "" echo %~8 >>patch
- if "%~9" NEQ "" echo %~9 >>patch
- call :packagemod
- )
- :packagemod
- SETLOCAL ENABLEDELAYEDEXPANSION
- set cmdstr=MAKECAB /v3 /D CompressionType=LZX /D CompressionMemory=21 /D MaxDiskSize=CDROM /D Cabinet=On /D Compress=On /D FolderSizeThreshold=5000000 /D DiskDirectoryTemplate="%~dp1." /D CabinetNameTemplate="Por54_Profiles.CAB"
- if exist cabstr del cabstr >nul
- for /f "delims=" %%i in (patch) do (
- set fullname=%%i
- set "fullname=!fullname:~0,-1!"
- if exist "!fullname!\" (
- for /f "delims=" %%a in ('dir "!fullname!" /s /b /a-d') do (
- SETLOCAL DISABLEDELAYEDEXPANSION
- call set "fn=%%~nxa"
- call set "fp1=%%a"
- call set "fp=%%~dpa"
- SETLOCAL ENABLEDELAYEDEXPANSION
- call set "fpr=%~dp0"
- call set fp=%%fp:!fpr!=%%
- call echo "%%fp1%%" "!fp!%%fn%%">>cabstr
- ENDLOCAL
- ENDLOCAL
- )
- ) else (
- echo "%%i" "%%~nxi">>cabstr
- )
- )
- %cmdstr% /F cabstr
复制代码 我大概是想疯了.... |