0

我有一个包含以下内容的文件

  aaaaaaaaa    filename1.txt
  bbbbbbbbbb   filename2.dat

我想读取这个文件并将数据单独存储到相关文件中。

例如:- aaaaa ---> filename1.txt

有人可以告诉我这样做的方法吗?如果您有任何示例,那将是一个真正的帮助!

子主

Set ctlpath = "\\Download_Directory\CA.ctl"
Set subDirectory = "AUB"
Set MkrExtention = ".mkr"

ReadCtl(ctlpath,subDirectory,MkrExtention )

End Sub

 Function ReadCtl(ctlFileName,ctlSubDirectory,MarkerFileExtension)

Const ForReading = 1
Const ForWriting = 2

Dim lineData,hashValue,fileName,fileToWrite

Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(ctlFileName) Then

Set objFile = objFSO.OpenTextFile(ctlFileName, ForReading)

Do Until objFile.AtEndOfStream

    lineData = objFile.ReadLine
    hashValue =Split(lineData,"  ") (0)
    fileName =Split(lineData,"  ") (1)

    WriteFileText("\\Download"+ctlSubDirectory+"
\"+fileName+MarkerFileExtension,hashValue)

Loop

objFile.Close
objFSO.Close

End If

ReadCtl = True

End Function

Function WriteFileText(sFilePath, sText)

Dim objFSO1 'As FileSystemObject
Dim objTextFile 'As Object

Set objFSO1 = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO1.CreateTextFile(sFilePath, True)

' Write hash data in to the file .mkr file
objTextFile.Write (sText)

objTextFile.Close
objFSO1.Close

 End Function
4

1 回答 1

1

好久没问这个了,没想到没人回答,很简单。希望你还在,反正这里供参考。当然,这不是真正的哈希,例如在 Ruby 中,但我保留了足够的脚本以便您进行比较。

ReadCtl("file2hash1.txt")

function ReadCtl(ctlFileName)
  const ForReading = 1, ForWriting = 2, ForAppending = 8, createIfNeeded = true
  set oFso = createObject("Scripting.FileSystemObject")
  Set oRegExpre = new RegExp
  oRegExpre.Global = true
  oRegExpre.Pattern = "(.*) +(.*)"
  if oFso.FileExists(ctlFileName) then
    set objFileRead  = oFso.OpenTextFile(ctlFileName, ForReading)
    do until objFileRead.AtEndOfStream
      lineData = objFileRead.ReadLine
      hashValue = oRegExpre.Replace(lineData,"$1")
      fileName  = oRegExpre.Replace(lineData,"$2")
      if oFso.fileExists(fileName) then
        modus = ForAppending
      else
        modus = ForWriting
      end if
      set objFileWrite = oFso.OpenTextFile(fileName, modus, createIfNeeded)
      objFileWrite.writeLine hashValue
      objFileWrite.close
    loop
    objFileRead.close
  end if
  set oFso = nothing
end function
于 2012-06-01T15:10:21.067 回答