需要 VBScript 问题帮助 [英] VBScript Issue Help Required
问题描述
我需要一个脚本,它可以在 Windows 操作系统 (Windows Server 2003) 上运行并从任何驱动器中提取信息,列出包含以下字段的所有文件和文件夹:服务器非常大并且在我们的域内.
I need a script that can run and pull information from any drive on a Windows operating system (Windows Server 2003), listing all files and folders which contain the following fields: The server is quite big and is within our domain.
所需信息为:
- 完整文件路径(例如 C:\Documents and Settings\user\My Documents\testPage.doc)
- 文件类型(例如 Word 文档、电子表格、数据库等)
- 尺寸
- 创建时间
- 上次修改时间
- 上次访问时间
脚本还需要将该数据转换为 CSV 文件,稍后我可以在 Excel 中修改和处理该文件.我可以想象这些数据会很大,但我仍然需要它.我在服务器上以管理员身份登录,脚本还需要处理受保护的文件.和之前的帖子一样,我读到如果处理这些文件,脚本将停止.我需要确保没有跳过任何文件.
Also the script will need to convert that data to a CSV file, which later on I can modify and process in Excel. I can imagine that this data will be huge but I still need it. I am logged in as an administrator on the server and the script will need to also process protected files. As in previous posts I have read that the script will stop if such files are processed. I need to make sure that not a single file is skipped.
请注意,我之前已经问过这个问题,但仍然没有一个有效的脚本.
Set objFS=CreateObject("Scripting.FileSystemObject")
WScript.Echo Chr(34) & "Full Path" &_
Chr(34) & "," & Chr(34) & "File Size" &_
Chr(34) & "," & Chr(34) & "File Date modified" &_
Chr(34) & "," & Chr(34) & "File Date Created" &_
Chr(34) & "," & Chr(34) & "File Date Accessed" & Chr(34)
Set objArgs = WScript.Arguments
strFolder = objArgs(0)
Set objFolder = objFS.GetFolder(strFolder)
Go (objFolder)
Sub Go(objDIR)
If objDIR <> "\System Volume Information" Then
For Each eFolder in objDIR.SubFolders
Go eFolder
Next
End If
For Each strFile In objDIR.Files
WScript.Echo Chr(34) & strFile.Path & Chr(34) & "," &_
Chr(34) & strFile.Size & Chr(34) & "," &_
Chr(34) & strFile.DateLastModified & Chr(34) & "," &_
Chr(34) & strFile.DateCreated & Chr(34) & "," &_
Chr(34) & strFile.DateLastAccessed & Chr(34)
Next
End Sub
<小时>
我目前正在使用命令行来运行它:
I am currently using the command-line to run it:
c:\test> cscript //nologo Test.vbs "c:\" > "C:\test\Output.csv"
脚本不起作用.我不知道为什么.
The script is not working. I don't know why.
推荐答案
在使用 Cscript 时正确地将 cmd-line args 传递给 vbs
<小时>-修改 cmd-line 语句如下(去掉>")
Properly passing cmd-line args to vbs when using Cscript
-Modify the cmd-line statement as follows (drop the ">")
c:\test> cscript //nologo Test.vbs "c:\" "C:\test\Output.csv"
-接下来在脚本中,您可以按如下方式访问 cmd 行参数
-Next inside the script you can access the cmd-line parameters as follows
strFolder = WScript.Arguments.Item(0)
strFile = WScript.Arguments.Item(1)
我希望现在您可以访问这些文件并在 csv 文件中正确列出它们.:-)
I hope now you can access the files and list them properly in the csv-file. :-)
好运!!
- 简历
GoodLUCK!!
- CVS
这篇关于需要 VBScript 问题帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!