1

你好,我的名字是丹尼斯,我有以下目录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 用于文档的第一个 tif 页面,DocId2,,DocId,,,, 用于文档的其他 tif-ages

目前,我制作了以下脚本:

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

我的问题是:

  • 如何计算每个文档的页数?
  • 如上所示,如何使用图像的文件名编写文本文件。

任何帮助是极大的赞赏 :-)

4

1 回答 1

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
于 2013-10-30T12:31:14.113 回答