我想要写一个VBS脚本,首先从文件path.txt中读取到一个路径 ,比如读取到"C:\Program Files (x86)\System Protect Software\" 然后,我要在这个路径下的子目录ShutdownScript下创建一个文件remotecomputer.txt,并写入字串test我的代码如下,但是为何老提示路径错误呢?是不是路径中有双引号呢?pathname="path.txt"
Set fso1 = CreateObject("scripting.FileSystemObject")
if (fso1.fileexists(pathname)) then
set ts1=fso1.opentextfile(pathname,1,true)
end if
strpath=ts1.readline
ts1.Closefilename=strpath+"\ShutdownScript\remotecomputer.txt"Set fso = CreateObject("scripting.FileSystemObject")
if (fso.fileexists(filename)) then
set ts=fso.opentextfile(filename,8,true)
ts.WriteLine ("test")
ts.Close
else
Set ts = fso.CreateTextFile(filename, True)
ts.WriteLine ("test")
ts.Close
end if
Set fso1 = CreateObject("scripting.FileSystemObject")
if (fso1.fileexists(pathname)) then
set ts1=fso1.opentextfile(pathname,1,true)
end if
strpath=ts1.readline
ts1.Closefilename=strpath+"\ShutdownScript\remotecomputer.txt"Set fso = CreateObject("scripting.FileSystemObject")
if (fso.fileexists(filename)) then
set ts=fso.opentextfile(filename,8,true)
ts.WriteLine ("test")
ts.Close
else
Set ts = fso.CreateTextFile(filename, True)
ts.WriteLine ("test")
ts.Close
end if
"C:\download\"
在DOS下,用
cscript //d a.vbs
来调试你的代码,错误在这一行:
Set ts = fso.CreateTextFile(filename, True)
错误的文件名或号码
主要是:
filename ""C:\download\"\ShutdownScript\remotecomputer.txt" String剩下的应该不用说了吧
vbs中对于有空格的路径需要转换成短路径
WScript.Echo CreateObject("Scripting.FileSystemObject").GetFolder("C:\Program Files\Java").ShortPath
我看不出filename有什么问题呀我支持
但是结果确实“路径未找到”
strpath中,获取到的路径是"C:\Program Files\System Protect Software\"filename=strpath+“ShutdownScript\remotecomputer.txt”
就是这句话中,如何先去掉strpath中的双引号,然后再相加
你检查strpath,也就是path.txt文件中第一行,不应该两端有双引号。
是自动的读取,我读取的就加了双引号所以我想问,如何能去掉这个双引号
strpath=mid(strpath,2,len(strpath)-2)