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 に答える