gpt4 book ai didi

Vbscript 搜索所有带有扩展名的文件并将它们保存到 CSV

转载 作者:行者123 更新时间:2023-12-03 15:10:02 24 4
gpt4 key购买 nike

我正在尝试编写一个脚本,该脚本将搜索 C:\及其所有子文件夹以查找特定扩展名,并将所有主题保存到 CSV 文件中。我试过这个,但无济于事:

Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "C:\"

Set objFolder = objFSO.GetFolder(objStartFolder)
Wscript.Echo objFolder.GetExtensionName("*.txt")

Set colFiles = objFolder.Files

For Each objFile in colFiles
If objFile.Extension = "pfx" Then
Wscript.Echo objFile.Name
End If
Next
Wscript.Echo

ShowSubfolders objFSO.GetFolder(objStartFolder)

Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
Wscript.Echo Subfolder.Path
Set objFolder = objFSO.GetFolder(Subfolder.Path)
Set colFiles = objFolder.Files
For Each objFile in colFiles
Wscript.Echo objFile.Name
Next
Wscript.Echo
ShowSubFolders Subfolder
Next

Set WScript = CreateObject("WScript.Shell")

End Sub

我不认为我在这里走的是正确的道路。我至少不精通 vb 脚本,它恰好是我唯一被允许使用的东西。

最佳答案

干得好:

Option Explicit 'force all variables to be declared

Const ForWriting = 2
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")

Dim objTS 'Text Stream Object
Set objTS = objFSO.OpenTextFile("C:\Output.txt", ForWriting, True)

Recurse objFSO.GetFolder("C:\")
objTS.Close()

Sub Recurse(objFolder)
Dim objFile, objSubFolder

For Each objFile In objFolder.Files
If LCase(objFSO.GetExtensionName(objFile.Name)) = "pfx" Then
objTS.WriteLine(objfile.Path)
End If
Next

For Each objSubFolder In objFolder.SubFolders
Recurse objSubFolder
Next
End Sub

关于Vbscript 搜索所有带有扩展名的文件并将它们保存到 CSV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18920310/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com