编辑每行文字

时间:2015-08-11 11:14:02

标签: text vbscript edit

我有一个包含60k +目录行的文本文件。如何编辑每一行:

C:\AJ\RPG Maker\Whisper of a Rose\OST\39 The Jewel (extended mix).mp3

对此:

ROBOCOPY "C:\AJ\RPG Maker\Whisper of a Rose\OST" "E:\AJ\RPG Maker\Whisper of a Rose\OST" "39 The Jewel (extended mix).mp3"

我正在考虑使用VBScript,但我无法获得更多信息,因为我不知道它:

Set objFS = CreateObject("Scripting.FileSystemObject")
strFile = "c:\file.txt"
Set objFile = objFS.OpenTextFile(strFile)
Do Until objFile.AtEndOfStream
    strLine = objFile.ReadLine
    If 
    End If 
    WScript.Echo strLine
Loop

1 个答案:

答案 0 :(得分:0)

由于FileSystemObject不允许编辑文件,因此请创建一个单独的文件来包含您的输出:

Set objFile2 = objFS.CreateTextFile("c:\out.txt", True)

然后,使用你已经创建的循环:

Do Until objFile.AtEndOfStream

    strLine = objFile.ReadLine

    ' Get the parent folder and the file name...
    strFolder = objFS.GetParentFolderName(strLine)
    strFile   = objFS.GetFileName(strLine)

    ' Write the command to the new output file...
    objFile2.Write "ROBOCOPY "
    objFile2.Write Chr(34) & strFolder & Chr(34) & " "
    objFile2.Write Chr(34) & "E" & Mid(strFolder, 2) & Chr(34) & " "
    objFile2.Write Chr(34) & strFile & Chr(34) & vbCrLf

Loop

这里没有什么太棘手的。只需使用FileSystemObject提供的方法提取文件名的一部分,然后连接字符串以创建输出。 Chr(34)用于表示输出文件中的引号字符。