Board logo

标题: [文件操作] 批处理怎样修改OUTLOOK签名文件? [打印本页]

作者: springcm    时间: 2008-5-14 11:02     标题: 批处理怎样修改OUTLOOK签名文件?

一般OUTLOOK 的签名文件位于%userprofile%/Application Data\Microsoft\Signatures 下有的3个文件:分别为“*.txt , *.rtf, 和*.htm"
我用echo *****>>输出到*.txt ,打开新文件后发现所有新追加内容均为乱码, 请大家帮忙解决下。

或者能否提供一份现有代码, 万分感谢!
作者: springcm    时间: 2008-5-15 20:38

没人回复自己顶下,问题已解决.
作者: namejm    时间: 2008-5-15 22:00

  是怎么解决掉的呢?不妨说出来,让后来者少走弯路。
作者: springcm    时间: 2008-5-17 20:09

其实很简单,先用type signature.txt>>temp.txt
然后可以用for语句对temp.txt文件正常处理.
example:
  1. :: To change txt file ============================
  2. :: Because the different code, try to use type file to rebuild *.txt files.
  3. setlocal enabledelayedexpansion
  4. set workpath=%userprofile%\Application Data\Microsoft\Signatures
  5. if exist %temp%\txtroot rd /s /q %temp%\txtroot
  6. mkdir %temp%\txtroot
  7. set txtroot=%temp%\txtroot
  8. set txtfiles=%temp%\txtfiles.txt
  9. if exist !txtfiles! del !txtfiles! /f /q
  10. dir /b "!workpath!\*.txt" >>!txtfiles!
  11. for /f "delims=/ tokens=*" %%a in (!txtfiles!) do (
  12. type "!workpath!\%%a">>"%temp%\txtroot\%%a"
  13. set path="%temp%\txtroot\%%a"
  14. for /f "delims=/ tokens=*" %%b in (%temp%\temp.txt) do echo %%b >>!path!
  15. copy /y !path! "!workpath!\%%a">nul
  16. )
  17. 在这里的3个文件中,对*.rtf文件最难处理.不能直接用输出符>>进行操作:
  18. 我的处理如下:
  19. :: To change rtf file ==============================
  20. :: Replace the first and the second content of original *.rtf
  21. :: By {\f0\fswiss\fcharset134 Simsun;} first line
  22. :: By {\f1\fmodern Simsun;} second line
  23. set rtffiles=%temp%\rtffiles.txt
  24. if exist !rtffiles! del !rtffiles! /f /q
  25. if exist %temp%\rtfroot rd /s /q %temp%\rtfroot
  26. mkdir %temp%\rtfroot
  27. set rtfroot=%temp%\rtfroot
  28. dir /b "!workpath!\*.rtf" >>!rtffiles!
  29. for /f "delims=~~ tokens=*" %%f in (!rtffiles!) do (
  30.     set rtfpath="!workpath!\%%f"
  31.     rem set rtfname=%%f
  32.     echo Modifying !rtfpath!
  33.     set flag=0
  34.     for /f "tokens=* usebackq" %%g in (!rtfpath!) do (
  35.     if !flag!==0 (echo %%g>>!rtfroot!\%%f
  36.                   echo {\f0\fswiss\fcharset134 Simsun;}>>!rtfroot!\%%f
  37.                   echo {\f1\fmodern Simsun;}>>!rtfroot!\%%f
  38.                   )
  39.     set flag=1
  40.     )
  41.     )
  42. rem echo the content of original *.rtf which was begining of 3 lines but final line.
  43. rem echo them to the folder %temp%\rtfroot
  44. for /f "delims=~~ tokens=*" %%f in (!rtffiles!) do (
  45.     set rtfpath="!workpath!\%%f"
  46.     for /f "skip=3 tokens=* usebackq" %%g in (!rtfpath!) do (
  47.     if not "%%g"=="{\*\htmltag3 \par }}" echo %%g>>!rtfroot!\%%f
  48.     )
  49.     for /f "delims= tokens=*" %%l in (%myfiles%\rtf.txt) do echo %%l>>!rtfroot!\%%f
  50.     )
  51. copy /y !rtfroot!\*.* "!workpath!\*.*">nul
复制代码

[ 本帖最后由 springcm 于 2008-6-1 19:57 编辑 ]




欢迎光临 批处理之家 (http://bathome.net./) Powered by Discuz! 7.2