其实很简单,先用type signature.txt>>temp.txt
然后可以用for语句对temp.txt文件正常处理.
example:
- :: To change txt file ============================
- :: Because the different code, try to use type file to rebuild *.txt files.
- setlocal enabledelayedexpansion
- set workpath=%userprofile%\Application Data\Microsoft\Signatures
- if exist %temp%\txtroot rd /s /q %temp%\txtroot
- mkdir %temp%\txtroot
- set txtroot=%temp%\txtroot
- set txtfiles=%temp%\txtfiles.txt
- if exist !txtfiles! del !txtfiles! /f /q
- dir /b "!workpath!\*.txt" >>!txtfiles!
- for /f "delims=/ tokens=*" %%a in (!txtfiles!) do (
- type "!workpath!\%%a">>"%temp%\txtroot\%%a"
- set path="%temp%\txtroot\%%a"
- for /f "delims=/ tokens=*" %%b in (%temp%\temp.txt) do echo %%b >>!path!
- copy /y !path! "!workpath!\%%a">nul
- )
- 在这里的3个文件中,对*.rtf文件最难处理.不能直接用输出符>>进行操作:
- 我的处理如下:
- :: To change rtf file ==============================
- :: Replace the first and the second content of original *.rtf
- :: By {\f0\fswiss\fcharset134 Simsun;} first line
- :: By {\f1\fmodern Simsun;} second line
- set rtffiles=%temp%\rtffiles.txt
- if exist !rtffiles! del !rtffiles! /f /q
- if exist %temp%\rtfroot rd /s /q %temp%\rtfroot
- mkdir %temp%\rtfroot
- set rtfroot=%temp%\rtfroot
- dir /b "!workpath!\*.rtf" >>!rtffiles!
- for /f "delims=~~ tokens=*" %%f in (!rtffiles!) do (
- set rtfpath="!workpath!\%%f"
- rem set rtfname=%%f
- echo Modifying !rtfpath!
- set flag=0
- for /f "tokens=* usebackq" %%g in (!rtfpath!) do (
- if !flag!==0 (echo %%g>>!rtfroot!\%%f
- echo {\f0\fswiss\fcharset134 Simsun;}>>!rtfroot!\%%f
- echo {\f1\fmodern Simsun;}>>!rtfroot!\%%f
- )
- set flag=1
- )
- )
- rem echo the content of original *.rtf which was begining of 3 lines but final line.
- rem echo them to the folder %temp%\rtfroot
- for /f "delims=~~ tokens=*" %%f in (!rtffiles!) do (
- set rtfpath="!workpath!\%%f"
- for /f "skip=3 tokens=* usebackq" %%g in (!rtfpath!) do (
- if not "%%g"=="{\*\htmltag3 \par }}" echo %%g>>!rtfroot!\%%f
- )
- for /f "delims= tokens=*" %%l in (%myfiles%\rtf.txt) do echo %%l>>!rtfroot!\%%f
- )
- copy /y !rtfroot!\*.* "!workpath!\*.*">nul
复制代码
[ 本帖最后由 springcm 于 2008-6-1 19:57 编辑 ] |