你好我的名字是丹尼斯,我有以下目录IMAGES\
:
EX0010040324303-001.tif
EX0010040324303-002.tif
EX0010040324303-003.tif
EX0020943843934-001.tif
EX0020943843934-002.tif
EX0030673452099-001.tif
EX0030673452099-002.tif
我想要什么?
通过目录和循环 编译文本文件如下:
EX0010040324303,,IMAGES\EX0010040324303-001.tif,Y,,,3
EX0010040324303,,IMAGES\EX0010040324303-002.tif,,,,
EX0010040324303,,IMAGES\EX0010040324303-003.tif,,,,
EX0020943843934,,IMAGES\EX0020943843934-001.tif,Y,,,2
EX0020943843934,,IMAGES\EX0020943843934-001.tif,,,,
EX0030673452099,,IMAGES\EX0030673452099-001.tif,Y,,,2
EX0030673452099,,IMAGES\EX0030673452099-002.tif,,,,
所以: DocId2,DocId,Y ,,, NumberOfPages,用于doc和。的第一个tif页面 DocId2,DocId ,,,,用于doc的其他tif-age
目前,我制作了以下剧本:
Function readCompleteText(inputReadLocation, OutputwriteLocation)
Const ForReading = 1
Dim lenInputReadLocation
Dim docId
Dim docId2
Dim oStream
Dim translationFileContents
Dim inputText
lenInputReadLocation = LEN(inputReadLocation)
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set FileList = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='"& inputReadLocation &"'} Where " _
& "ResultClass = CIM_DataFile")
For Each objFile In FileList
Dim i
i = 0
docId = RIGHT(objFile.Name,(LEN(objFile.Name)-lenInputReadLocation-1))
docId2 = LEFT(docId, LEN(docId)-4)
MyArray = Split(docId2, "-")
EXnumber = MyArray(0)
PageNumber = MyArray(1)
'inputText = EXnumber &",,"& docId &",,,,"
Next
oStream.WriteText inputText,0
oStream.SaveToFile OutputwriteLocation
oStream.close
oStream = Nothing
End Function
我的问题是:
非常感谢任何帮助: - )
答案 0 :(得分:1)
当您提取文件的信息时,请将这些信息放入您通过其ID存储在字典中的(TifFile)对象集合中:
(遗憾的是我无法测试代码,但你会得到这个想法)
class TifFile
Public FileName
Public DocId
Public DocId2
Public ExNumber
Public PageNumber
End Class
'[..snip..]
Set TifFileCollection = CreateObject("Scripting.Dictionary")
For Each objFile In FileList
' Do some parsing here
docId = RIGHT(objFile.Name,(LEN(objFile.Name)-lenInputReadLocation-1))
docId2 = LEFT(docId, LEN(docId)-4)
exNumber = Split(docId2, "-")(0)
pageNumber = Split(docId2, "-")(1)
' Put it in an object
Set oTifFile = new TifFile
oTifFile.FileName = objFile.Name
oTifFile.DocId = docId
oTifFile.DocId2 = docId2
oTifFile.ExNumber = exNumber
oTifFile.PageNumber = pageNumber
' Add the file to a collection
if not TifFileCollection(DocId).Exists then
Set TifFileCollection.Item(DocId) = CreateObject("System.Collections.ArrayList")
end if
TifFileCollection.Item(DocId).Add oTifFile
Next
' Iterate through all files
prefix = "IMAGES\"
distinctNumberOfFiles = TifFileCollection.Count
For each id in TifFileCollection.Keys
Set collectionOfTifFilesWithSameId = TifFileCollection(id)
numberOfFilesWithSameId = collectionOfTifFilesWithSameId.Count
for each oTifFile in collectionOfTifFilesWithSameId.ToArray()
If (numberOfFilesWithSameId > 1) and (oTifFile.PageNumber = "001") then
multipage = "Y"
pageCount = numberOfFilesWithSameId
else
multipage = "N"
pageCount = ""
End if
' Output:
MsgBox join(array( _
oTifFile.DocId, _
"", _
prefix & oTifFile.FileName, _
multipage, _
"", "", _
pageCount), ",")
Next
Next