创建行并将其写入文件 [英] Creating and writing lines to a file

查看:29
本文介绍了创建行并将其写入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 vbscript 中创建文件并写入行?

Is it possible to create a file and write lines to it in vbscript?

类似于 echo in bat 文件(echo something >sometextfile.txt).

根据脚本路径执行 vbscript 时会创建一个 autorun.inf 文件来执行特定程序 (\smartdriverbackup\sdb.exe).

On execution of the vbscript depending on the path of the script would create an autorun.inf file to execute a particular program (\smartdriverbackup\sdb.exe).

另外,如何从完整的文件路径中删除/删除驱动器号?

Also how can I strip/remove the drive letter from the complete file path?

推荐答案

Set objFSO=CreateObject("Scripting.FileSystemObject")

' How to write file
outFile="c:\test\autorun.inf"
Set objFile = objFSO.CreateTextFile(outFile,True)
objFile.Write "test string" & vbCrLf
objFile.Close

'How to read a file
strFile = "c:\test\file"
Set objFile = objFS.OpenTextFile(strFile)
Do Until objFile.AtEndOfStream
    strLine= objFile.ReadLine
    Wscript.Echo strLine
Loop
objFile.Close

'to get file path without drive letter, assuming drive letters are c:, d:, etc
strFile="c:\test\file"
s = Split(strFile,":")
WScript.Echo s(1)

这篇关于创建行并将其写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆