0

我写了一个有效的脚本。它现在所做的是通过目录查找给定文件并返回第二行第四选项卡(RXC193)上的内容,并将文件重命名为从文件中找到的文件,如下所示:

@Program @RxBIN @RXPCN @RxGroup @MemberID @WebsiteE @WebsiteS @VerticalLogo @TextLogo RXCUT 013824 RXCUT
RXC193 RXC5FHXF9 www.rxcut.com/HBG www.rxcut.com/HBG/es P:\RxCut\In Design Implementation\RXC193

我需要这个脚本能够做的是遍历目录并通过这个 RXC##### 重命名所有文件。这是脚本:

Call TwoDimensionArrayTest

Sub TwoDimensionArrayTest
' Version 1.0
' Writtem by Krystian Kara
' Dated 25-Jan-2009


    Dim fso
    Dim oFile
    Dim arrline
    Dim arrItem
    Dim objFolder
    Dim i
    Dim arrMain()
    Dim sFileLocation, strResults

    Const forReading = 1

' The file contains on each line:
    ' Text1 (tab) Text2 (tab) Text3 (tab) Text4
    ' Text5 (tab) Text6 (tab) Text7 (tab) Text8
'etc etc


    Set fso = CreateObject("Scripting.FileSystemObject")
        sFileLocation = "file 2.txt"

        Set oFile = fso.OpenTextFile(sFileLocation, forReading, False)

    Do While oFile.AtEndOfStream <> True
        strResults = oFile.ReadAll
    Loop

' Close the file
    oFile.Close

' Release the object from memory
    Set oFile = Nothing

' Return the contents of the file if not Empty
    If Trim(strResults) <> "" Then

        ' Create an Array of the Text File
        arrline = Split(strResults, vbNewLine)
    End If

    For i = 0 To UBound(arrline)
        If arrline(i) = "" Then
            ' checks for a blank line at the end of stream
            Exit For
        End If 

        ReDim Preserve arrMain(i)

            arrMain(i) = Split(arrline(i), vbTab)

    Next

    fso.MoveFile "file 2.txt", arrMain(1)(3) & ".txt"

End Sub ' TwoDimensionArrayTest

在此先感谢,乔

4

2 回答 2

0

这是最终的无错误代码!最后让它搜索我的 Tab-delimited.txt 文件目录并从第二行第三个选项卡(组号)中抓取,然后将文件重命名为其对应的组号!耶!

这是最终的无错误代码!:

Call TwoDimensionArrayTest

子二维数组测试

Dim fso Dim oFile Dim arrline Dim arrItem Dim i Dim arrMain() Dim sFileLocation, strResults

Const forReading = 1

strFolder = "C:\Documents and Settings\jmituzas.NMCLLC\Desktop\desktop2\New Folder (2)\datafiles" 设置 objFSO = CreateObject("Scripting.FileSystemObject") For Each objFile In objFSO.GetFolder(strFolder).Files If对(LCase(objFile.Name), 4) = LCase(".txt") 然后

    ' The file contains on each line:
' Text1 (tab) Text2 (tab) Text3 (tab) Text4
' Text5 (tab) Text6 (tab) Text7 (tab) Text8

'等等等等

设置 fso = CreateObject("Scripting.FileSystemObject") sFileLocation = objFile.Name

    Set oFile = fso.OpenTextFile(objFile.Name, forReading, False)

Do While oFile.AtEndOfStream <> True
    strResults = oFile.ReadAll
Loop

' Close the file
oFile.Close

' 从内存中释放对象 Set oFile = Nothing

' 如果不为空则返回文件内容 If Trim(strResults) <> "" Then

    ' Create an Array of the Text File
    arrline = Split(strResults, vbNewLine)
End If

For i = 0 To UBound(arrline)
    If arrline(i) = "" Then
        ' checks for a blank line at the end of stream
        Exit For
    End If 

    ReDim Preserve arrMain(i)

        arrMain(i) = Split(arrline(i), vbTab)

Next

  fso.MoveFile sFileLocation, arrMain(1)(3) & ".txt"

End If Next End Sub ' TwoDimensionArrayTest

于 2010-09-03T16:56:15.300 回答
0

一种方法是在子过程中参数化文件名,以便可以为不同的文件多次调用它,如下所示:

Sub TwoDimensionArrayTest(fileName) 'you may want a more descriptive name

    ' ...
    sFileLocation = fileName
    ' ...

End Sub

然后,编写一个遍历您的目录的循环,每次调用您的子目录:

Dim fso, folder

Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder("Your Folder Name")
For Each file In folder.Files
    TwoDimensionArrayTest file.Path
Next
于 2010-09-01T18:04:22.187 回答