0

在此脚本中,我尝试重命名文件夹中的所有文件。我将使用Instr(1, strText, "(Amtlicher Gemeindeschlüssel = " ...)从每个文本文件本身收集新名称。所以所有 jsp 文件都应继续进行。但我几乎在最后得到一个对象错误:800A01A8 - 需要对象。任何人都可以帮我替换对象 strVerz.files以便代码正常工作。 提前谢谢你。迈克尔

Dim objFso, strFolder

' Begin Main

Set objFso = CreateObject("Scripting.FileSystemObject")
strFolder = objFso.GetParentFolderName(WScript.ScriptFullName)  

If objFso.FolderExists(strFolder) Then
    Call GetJspFiles(objFso.GetFolder(strFolder))
End If

Set objFso = Nothing

' End Main

Sub GetJspFiles(ByRef objFolder)
    Dim objFile, objSubFolder

    For Each objFile In objFolder.Files
        If LCase(objFso.GetExtensionName(objFile.Name)) = "jsp" Then
            Call JSPRename(objFile.Path, objFolder.Path)
        End If
    Next

    For Each objSubFolder In objFolder.SubFolders
      Call GetJspFiles(objSubFolder)
    Next
' objFile.Close

End Sub

Sub JSPRename(ByRef strPath, ByRef strFolder)
    Dim arrText, strText, strTextLine, Position , objJspFile, newFilename, strVerz

    Set objJspFile = objFso.OpenTextFile(strPath)

    arrText = Split(objJspFile.ReadAll, vbCrLf) ' split to lines

    For Each strTextLine In arrText
      If strTextLine <> "" Then
         strText = Trim(strTextLine)

       If Instr(1,strText,"(Amtlicher Gemeindeschlüssel",1) Then
        Position=Instr(1, strText, "(Amtlicher Gemeindeschlüssel =",1)
       newFilename=mid(strText,Position+31, 8)

       else
       end if
      end if

    Next

    strVerz=objFSO.GetParentFoldername(WScript.ScriptFullName)
    strNewName = strVerz & "\" & newFilename & ".jsp" 

    ' Wscript.echo strNewName & vbcrlf & strVerz.files '!! only for Showing the results

     objFSO.MoveFile strVerz.files, strNewName <- Here I get the error

     objJspFile.Close

End Sub
4

1 回答 1

0

似乎 的目的JSPRename是重命名由strPath. 在这种情况下,调用MoveFile应该如下所示:

objFSO.MoveFile strPath, strNewName
于 2012-07-15T23:44:46.073 回答