我有一个 VBS 脚本,需要每月运行一次,它捕获文件信息,例如文件名、类型、修改日期等。当我处理每个文件时,它会将其全部保存到 CSV 文件中,以便我可以在 Excel 上处理它。
为了运行脚本,我设置了一个批处理文件 .bat
问题是我需要某种 GUI 界面,以便在运行批处理或 vbs 文件时,它会要求用户输入要扫描的驱动器号。
这是我的代码:
test.vbs:
Option Explicit
Dim objFS, objFld
Dim objArgs
Dim strFolder, strDestFile, blnRecursiveSearch
Dim strLines()
Dim i
Dim strCsv
i = 0
' 'Get the commandline parameters
' Set objArgs = WScript.Arguments
' strFolder = objArgs(0)
' strDestFile = objArgs(1)
' blnRecursiveSearch = objArgs(2)
'###################################
'MAKE SURE THESE VALUES ARE CORRECT
'###################################
strFolder = "C:\"
strDestFile = "C:\test\Output.csv"
blnRecursiveSearch = True
'Create the FileSystemObject
Set objFS=CreateObject("Scripting.FileSystemObject")
'Get the directory you are working in
Set objFld = objFS.GetFolder(strFolder)
'Now get the file details
GetFileDetails objFld, blnRecursiveSearch
'Write the csv file
Set strCsv = objFS.CreateTextFile(strDestFile, True)
strCsv.Write Join(strLines, vbCrLf)
'Close and cleanup objects
strCsv.Close
Set strCsv = Nothing
Set objFld = Nothing
Set strFolder = Nothing
Set objArgs = Nothing
Private Sub GetFileDetails(fold, blnRecursive)
Dim fld, fil
dim strLine(5)
If blnRecursive Then
'Work through all the folders and subfolders
For Each fld In fold.SubFolders
GetFileDetails fld, True
Next
End If
'Now work on the files
For Each fil in fold.Files
strLine(0) = fil.Path
strLine(1) = fil.Type
strLine(2) = fil.Size
strLine(3) = fil.DateCreated
strLine(4) = fil.DateLastModified
strLine(5) = fil.DateLastAccessed
Redim Preserve strLines(i)
strLines(i) = Join(strLine, ",")
i = i + 1
Next
end sub
还有run.bat
cscript.exe C:\script\test.vbs
如您所见,test.vbs 指定要扫描和捕获的部分。代码:strFolder = "C:\"
你最好的建议是什么,运行这个程序的人在 VB 方面的经验比我少得多,所以他们需要某种 GUI 界面,要求输入驱动器号,然后修改行代码strFolder = "C:\"
到他们输入的任何驱动器号,然后运行 test.vbs。