1
我得到了下面的代码来获取信息的文件指定的驱动器上,我跑了剧本反对票600 GB硬盘驱动器上我们的服务器之一,一段时间后,我得到的错误VBScript中出的字符串空间
超出字符串空间; “加入”。 34号线,字符2
对于此代码,文件script.vbs:
Option Explicit
Dim objFS, objFld
Dim objArgs
Dim strFolder, strDestFile, blnRecursiveSearch
''Dim strLines
Dim strCsv
''Dim i
'' i = 0
' 'Get the commandline parameters
' Set objArgs = WScript.Arguments
' strFolder = objArgs(0)
' strDestFile = objArgs(1)
' blnRecursiveSearch = objArgs(2)
'########################################
'SPECIFY THE DRIVE YOU WANT TO SCAN BELOW
'########################################
strFolder = "C:\"
strDestFile = "C:\InformationOutput.csv"
blnRecursiveSearch = True
'Create the FileSystemObject
Set objFS=CreateObject("Scripting.FileSystemObject")
'Get the directory you are working in
Set objFld = objFS.GetFolder(strFolder)
'Open the csv file
Set strCsv = objFS.CreateTextFile(strDestFile, True)
'' 'Write the csv file
'' Set strCsv = objFS.CreateTextFile(strDestFile, True)
strCsv.WriteLine "File Path,File Size,Date Created,Date Last Modified,Date Last Accessed"
'' strCsv.Write Join(strLines, vbCrLf)
'Now get the file details
GetFileDetails objFld, blnRecursiveSearch
'' 'Close and cleanup objects
'' strCsv.Close
'' 'Write the csv file
'' Set strCsv = objFS.CreateTextFile(strDestFile, True)
'' For i = 0 to UBound(strLines)
'' strCsv.WriteLine strLines(i)
'' Next
'Close and cleanup objects
strCsv.Close
Set strCsv = Nothing
Set objFld = Nothing
Set strFolder = Nothing
Set objArgs = Nothing
'---------------------------SCAN SPECIFIED LOCATION-------------------------------
Private Sub GetFileDetails(fold, blnRecursive)
Dim fld, fil
dim strLine(4)
on error resume next
If InStr(fold.Path, "System Volume Information") < 1 Then
If blnRecursive Then
'Work through all the folders and subfolders
For Each fld In fold.SubFolders
GetFileDetails fld, True
If err.number <> 0 then
LogError err.Description & vbcrlf & "Folder - " & fold.Path
err.Clear
End If
Next
End If
'Now work on the files
For Each fil in fold.Files
strLine(0) = fil.Path
strLine(1) = fil.Size
strLine(2) = fil.DateCreated
strLine(3) = fil.DateLastModified
strLine(4) = fil.DateLastAccessed
strCsv.WriteLine Join(strLine, ",")
if err.number <> 0 then
LogError err.Description & vbcrlf & "Folder - " & fold.Path & vbcrlf & "File - " & fil.Name
err.Clear
End If
Next
End If
end sub
Private sub LogError(strError)
dim strErr
'Write the csv file
Set strErr = objFS.CreateTextFile("C:\test\err.log", false)
strErr.WriteLine strError
strErr.Close
Set strErr = nothing
End Sub
RunMe.cmd
wscript.exe "C:\temp\script\script.vbs"
我怎样才能避免收到此错误?服务器驱动器是相当有点< ????我想象,CSV文件将至少40 MB。
编辑Guffa:
我在代码中注释了一些行,使用双蜱(''),所以你可以看到在哪里。
感谢您的快速回复子程序循环。我将修改我的脚本并再次运行它。我会让你知道结果。欢呼 – MalsiaPro 2010-02-22 14:14:17
我仍然遇到此问题错误“无效的过程调用或参数(第36行,字符5),您的解决方案增加字符串中的数据空间的大小,但有没有办法直接写入输出CSV文件而不是写入阵列/串,然后生成CSV输出。 – MalsiaPro 2010-02-23 12:31:45
的感谢是的,而不是存储在阵列中的线,你可以将它们直接写入文件。见上面我的编辑。 – Guffa 2010-02-23 13:37:25