我在编程方面非常新,但到目前为止我很享受。
也许一些提示让vbs fil返回?
到目前为止,我有这个:
(但它不会返回多少个文件的计数器,也不会分隔不同列中的字段)
Dim fso
Dim ObjOutFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set ObjOutFile = fso.CreateTextFile("OutputFiles.csv")
ObjOutFile.WriteLine("Type,File Name,File Path")
GetFiles("C:\Intel")
ObjOutFile.Close
WScript.Echo("Completed")
Function GetFiles(FolderName)
On Error Resume Next
Dim ObjFolder
Dim ObjSubFolders
Dim ObjSubFolder
Dim ObjFiles
Dim ObjFile
Set ObjFolder = fso.GetFolder(FolderName)
Set ObjFiles = ObjFolder.Files
For Each ObjFile In ObjFiles
ObjOutFile.WriteLine("File," & ObjFile.Name & "," & ObjFile.Path)
Next
Set ObjSubFolders = ObjFolder.SubFolders
For Each ObjFolder In ObjSubFolders
ObjOutFile.WriteLine("Folder," & ObjFolder.Name & "," & ObjFolder.Path)
GetFiles(ObjFolder.Path)
Next
End Function
先谢谢你们所有人! 你会在这里张贴一个非常感恩的女孩! :d
答案 0 :(得分:0)
这是我用来提取文件名/文件夹和路径的方法。
Sub PullFileFolderPaths()
Dim varDirectory As Variant
Dim flag As Boolean
Dim i As Integer
Dim strDirectory As String
strDirectory = "C:\Home\Preflight\"
i = 1
flag = True
varDirectory = Dir(strDirectory, vbDirectory)
While flag = True
If varDirectory = "" Then
flag = False
Else
Cells(i + 1, 1) = varDirectory
Cells(i + 1, 2) = strDirectory + varDirectory
'returns the next file or directory in the path
varDirectory = Dir
i = i + 1
End If
Wend
End Sub