我有一個VBS腳本,我需要按月運行,它捕獲文件信息,包括文件名稱,類型,修改日期等。當我處理每個文件時,它會將其全部保存到CSV文件中,以便我可以在Excel上處理它。用於運行VBS腳本的VB GUI界面
要運行腳本我建立一個批處理文件.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更經驗一些,所以他們需要某種圖形用戶界面接口來請求驅動器字母輸入然後修改行代碼strFolder = "C:\"
他們輸入的任何驅動器號,然後運行test.vbs。
任何幫助表示讚賞。
:)乾杯
檢查[此WSH VBS GUI](https://stackoverflow.com/a/47111556/2165759)解決方案。 – omegastripes 2017-11-09 15:16:43