私はループしたいファイルのディレクトリを持っており、ファイル名の一部をテンプレートdocのテキストに置き換えています。VBscriptテキストをファイル名の一部に置き換えます。
たとえば、1つのファイル名は「NV_AD32_city.dxf」です。ディレクトリ内のすべてのファイルは、2つのアンダースコアを使用して、XX_XXXX_string.dxfの同じファイル名パターンに従います。 『AD32_city』
どのように私はスクリプトのキャプチャを使用するかだろう、私は「_」最初の右への左にある文字列をキャプチャする必要がある「」ように、この例のために
テンプレート内のテキストを置き換えるアクティブなファイルのテキスト?私はオブジェクトを作成する必要があると思いますか?しかし、ディレクトリから現在のファイルに使用するオブジェクトは何ですか? +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++301あなたのコードを試して数日後、私はちょうど "それを得る"ではありません。私はそれが私が望むファイル名の文字列の部分を取るように設定されていることを理解していますが、私はループしている現在のファイルを使用するスクリプトをどのように教えますか?ここまでは私のスクリプトです。 Sub 'GetNewInputs'の下の20行目にコードがあります
Set fso = CreateObject("Scripting.FileSystemObject")
Option Explicit
Dim WritePath : WritePath = "S:\TempFolder\"
Dim OutFile : OutFile = "VEG_DXF-2-SHP_script-"
Dim WorkingFile : WorkingFile = GetFileContent(SelectFile())
Dim NewState, NewSection, NewArea
Dim OldState, OldSection, OldArea
Call GetNewInputs()
Call GetOldInputs()
Sub GetNewInputs()
NewState = UCase(InputBox("INPUT STATE:", _
"INPUT STATE", "SOCAL"))
NewSection = ("Section_" & InputBox("INPUT SECTION NUMBER:", _
"INPUT SECTION", "14"))
NewArea = "^[^_]+_(.*)\.dxf$"
End Sub
Private Sub GetOldInputs()
OldState = "XX"
OldSection = "_X"
OldArea = "ZZZZ"
End Sub
Function SelectFile()
SelectFile = vbNullString
Dim objShell : Set objShell = WScript.CreateObject("WScript.Shell")
Dim strMSHTA : strMSHTA = "mshta.exe ""about:" & "<" & "input type=file id=FILE>" _
&"<" & "script>FILE.click();new ActiveXObject('Scripting.FileSystemObject')" _
&".GetStandardStream(1).WriteLine(FILE.value);close();resizeTo(0,0);" & "<" & "/script>"""
SelectFile = objShell.Exec(strMSHTA).StdOut.ReadLine()
If SelectFile = vbNullString Then
WScript.Echo "No file selected or not a text file."
WScript.Quit
End If
End Function
Private Function GetFileContent(filePath)
Dim objFS, objFile, objTS
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFile = objFS.GetFile(filePath)
Set objTS = objFile.OpenAsTextStream(1, 0)
GetFileContent = objTS.Read(objFile.Size)
Set objTS = Nothing
End Function
For Each FileRefIn fso.GetFolder("S:\SOCAL\Section_14\Veg DXFs\").Files
NewFile = WorkingFile
NewFile = Replace(NewFile, OldState, NewState)
NewFile = Replace(NewFile, OldSection, NewSection)
NewFile = Replace(NewFile, OldArea, NewArea)
WriteFile NewFile, WritePath & OutFile & ".gms"
WScript.Echo NewArea
Next
Private Sub WriteFile(strLine,fileName)
On Error Resume Next
Dim objFSO, objFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
Do Until IsObject(objFile)
Set objFile = objFSO.OpenTextFile(fileName, 8, True)
Loop
objFile.WriteLine strLine
objFile.Close
End Sub
返信用のThx。あなたのコードを試して数日後、私はちょうど "それを得る"ではありません。私はそれが私が望むファイル名の文字列の部分を取るように設定されていることを理解していますが、私はループしている現在のファイルからスクリプトを取るように教えてもらえますか?これまでのスクリプトは以下の通りです: – Clutch