1

フォルダー内に約 30 個のサブフォルダー (各フォルダーは多くのサブフォルダーで構成されています) を持っています。各 SQL ファイルからテキストを置き換えようとしています。vbscript でこれにコードを書き、3 ~ 4 個のサブフォルダーでテストしましたが、完全に機能していました。 .しかし、すべてのフォルダーで実行しようとすると、ファイルが書き込まれません。

'Root path where all folders and files are present
'Change according to your requirement

strPath="W:\New Folder\Test1"

Set objFso = CreateObject("Scripting.FileSystemObject")

'To access folders
Set objFolder = objFso.GetFolder (strPath)

TraverseFolder (objFso.GetFolder(strPath))

Function TraverseFolder(FolderName)
    For Each fld in FolderName.SubFolders
        TraverseFolder(fld) 
        For Each flname in fld.Files 
            if objFso.GetExtensionName(flname.Path)="sql" then
                'msgbox fld.Path & "\" & objFso.GetFileName(flname.Path)

'After commenting whole below section,and running rest of code with
'the above mentioned msgbox every single folder and files are getting
'fetched but when i  uncomment below section, only some folders and
'files are getting displayed in msgbox'

                Const ForReading = 1
                Const ForWriting = 2

                Set objFile = objFso.OpenTextFile(fld.Path & "\" & objFso.GetFileName(flname.Path), 1)

                strText = objFile.ReadAll
                objFile.Close

                strText= Replace(strText, "A_", "L_")
                strText= Replace(strText, "A", "D")
                strText= Replace(strText, "Database\Sy", "Database\SQ")

                Set objFile = objFso.OpenTextFile(fld.Path & "\" & objFso.GetFileName(flname.Path), 2)

                objFile.WriteLine strText
                objFile.Close
            End If
        Next
    Next
End Function
4

1 に答える 1

1

とにかく(投稿したコードで)ForReadingおよびForWriting定数を使用していないようです。それらを削除するだけです。

于 2013-02-21T14:15:34.397 に答える