[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] 请教bat批处理,文件名或其存放路径名含有空格,需替换字符串也带有空格

致论坛的老师&大神:

请教关于bat批处理,有两个地方的空格导致不知该如何解决,1,待处理的文件名或其存放路径名含有空格,2.需要替换文件里边内容,该内容是带有空格的字符串。搜变全网没找到都满足的解决方案。

比方说有一个txt文档,他的文件名是: address update.txt,文件名或其存放路径名含有空格,
要替换的内容为: 000- woodlands drive 79,想将文本内所有的该字符串替换为 000- sembawang street 66



address update.txt文本内容如下:
  1. Update = Open( Concat( New_path, "000- woodlands drive 79.csv" ) );
  2. Update << select where( :RAW_VALUE == 0 );
  3. Update << Delete Rows;
  4. Update << New Column( "Batch",
  5. Character,
  6. Nominal,
  7. Formula(
  8. If(
  9. Contains( :ID, "ID001" ), "001",
  10. Contains( :ID, "ID002" ), "002",
  11. )
  12. )
  13. );
  14. Update << Move Selected Columns({“Batch”}, To First);
  15. Column( Update, "shift ID" ) << data type( Character );
  16. Column( Update, "shift ID" ) << Set Modeling Type( Nominal );
  17. Column( Update, "shift ID" ) << set name( "Batch ID" );
  18. For Each Row(
  19. Update,
  20. :Batch ID = Match( :Batch ID,
  21. "9653856", "shift1",
  22. "9673409", "shift2",
  23. "9653427", "shift1",
  24. "9663511", "shift2",
  25. "9653427", "shift1",
  26. "9663550", "shift2",
  27. "Unspecified"
  28. )
  29. );
  30. Update << New Column( "rename",
  31. Character,
  32. Nominal,
  33. Formula(
  34. If(
  35. Contains( :address, "param1" ), "000- woodlands drive 79",
  36. Contains( :address, "param2" ), "000- woodlands drive 79",
  37. Contains( :address, "param3" ), "000- woodlands drive 79",
  38. Contains( :address, "param4" ), "000- woodlands drive 79",
  39. Contains( :address, "param5" ), "000- woodlands drive 79",
  40. Contains( :address, "param6" ), "000- woodlands drive 79",
  41. )
  42. )
  43. );
  44. dtWaferLevel = Update << Split(
  45. Split By( :rename ),
  46. Split( :RAW_VALUE ),
  47. Group(
  48. :Batch,
  49. :Category,
  50. :LOT_ID,
  51. :Batch ID,
  52. ),
  53. Remaining Columns( Drop All )
  54. );
复制代码

回复 5# Batcher


    感谢老师,试过了,成功!

TOP

回复 3# qspringleaf
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. cd /d "C:\address name"
  4. (for /f "tokens=1* delims=:" %%i in ('findstr /n ".*" "address update.txt"') do (
  5.     set a=%%j
  6.     if "%%j"=="" (
  7.         echo;
  8.     ) else (
  9.         echo;!a:000- woodlands drive 79=000- sembawang street 66!
  10.     )
  11. ))>"address update.tmp"
  12. move /y "address update.tmp" "address update.txt"
复制代码
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

  1. @echo off
  2. setlocal enabledelayedexpansion
  3. set "f=c:\address name\address update.txt"
  4. (for /f "tokens=1* delims=:" %%i in ('findstr /n ".*" "%f%"') do (
  5. set a=%%j
  6. if "%%j"=="" (echo;) else (
  7. echo;!a:000- woodlands drive 79=000- sembawang street 66!
  8. )
  9. )>tmptmp
  10. move /y tmptmp %f%
  11. pause
复制代码

TOP

回复 2# idwma

感谢&#128591;,想再请教如果该文件 address update.txt的完整路径是c:\address name\address update.txt, 当字符串被替换完成后,如何实现自动保存在原路径下,并覆盖原文件。感激不尽。

TOP

  1. @echo off
  2. setlocal enabledelayedexpansion
  3. for /f "tokens=1* delims=:" %%i in ('findstr /n ".*" "address update.txt"') do (
  4. set a=%%j
  5. if "%%j"=="" (echo;) else (
  6. echo;!a:000- woodlands drive 79=000- sembawang street 66!
  7. )
  8. )
  9. pause
复制代码

TOP

返回列表