返回列表 发帖

[问题求助] 能否用VBS创建cmd文件

本帖最后由 nai 于 2014-11-8 23:10 编辑

如何用VBS创建CMD文件,并将代码写入到CMD文件中?
代码比如:

@echo off
cd.>B.txt
for /f "delims=" %%i in (A.txt) do (
find /i "%%i" B.txt||echo %%i>>B.txt
)


主要是如何处理有引号的句子

回复 1# nai
strFile = "0.bat"
strText = "@echo off" & vbCrLf & _
  "cd.>B.txt" & vbCrLf & _
  "for /f ""delims="" %%i in (A.txt) do (" & vbCrLf & _
  "find /i ""%%i"" B.txt||echo %%i>>B.txt" & vbCrLf & _
  ")"
Set fso = CreateObject("Scripting.filesystemobject")
set wTxt = fso.OpenTextFile(strFile, 2, True, 0)
wTxt.Write strText
wTxt.Close
Msgbox "创建完成!"COPY
引号的处理
输出:
符文 "a" 与 符文 "b" COPY
'输出:符 "a" 文 "b"
' 1. 字符串内部使用 "" 转义
str1 = "符 ""a"" 文 ""b"""
' 2. 字符串外部使用 Chr(34)
str2 = "符 " & Chr(34) & "a" & Chr(34) & " 文 " & Chr(34) & "b" & Chr(34)
Msgbox "str1=" & str1
Msgbox "str2=" & str2COPY
『千江有水千江月』千江有水,月映千江;万里无云,万里青天。    http://yu2n.qiniudn.com/

TOP

回复 2# yu2n
很好,很详细,谢谢

TOP

返回列表