使用 vbscript / hta 将文件夹中的所有文件加载到数组中?
Load all files within a folder into an array with vbscript / hta?
我想用 vbscipt/hta 将一个目录的所有文件加载到一个数组中,以便稍后按索引对它们进行排序和 "call"。我试过类似的方法,但没有用:
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFileFolder = "C:\"
Set objFolder = objFSO.GetFolder(objFileFolder)
Set colFiles = objFolder.Files
dim arrFileList()
For Each objFile in colFiles
ReDim Preserve arrFileList(UBound(arrFileList) + 1)
FileList(UBound(arrFileList)) = objFile.Name
Next
如有任何帮助,我将不胜感激!提前致谢
您需要更改两处内容,请参阅下面的新代码。在线评论。
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFileFolder = "C:\"
Set objFolder = objFSO.GetFolder(objFileFolder)
Set colFiles = objFolder.Files
dim arrFileList()
ReDim Preserve arrFileList(0) 'If you wish to use the array UBound later on you must redim this here
For Each objFile in colFiles
ReDim Preserve arrFileList(UBound(arrFileList) + 1)
arrFileList(UBound(arrFileList)) = objFile.Name ' Here you were calling FileList, not arrFileList
Next
您可以进一步整理/改进此代码,因为 arrFileList(0)
完成后将没有任何价值。
我想用 vbscipt/hta 将一个目录的所有文件加载到一个数组中,以便稍后按索引对它们进行排序和 "call"。我试过类似的方法,但没有用:
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFileFolder = "C:\"
Set objFolder = objFSO.GetFolder(objFileFolder)
Set colFiles = objFolder.Files
dim arrFileList()
For Each objFile in colFiles
ReDim Preserve arrFileList(UBound(arrFileList) + 1)
FileList(UBound(arrFileList)) = objFile.Name
Next
如有任何帮助,我将不胜感激!提前致谢
您需要更改两处内容,请参阅下面的新代码。在线评论。
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFileFolder = "C:\"
Set objFolder = objFSO.GetFolder(objFileFolder)
Set colFiles = objFolder.Files
dim arrFileList()
ReDim Preserve arrFileList(0) 'If you wish to use the array UBound later on you must redim this here
For Each objFile in colFiles
ReDim Preserve arrFileList(UBound(arrFileList) + 1)
arrFileList(UBound(arrFileList)) = objFile.Name ' Here you were calling FileList, not arrFileList
Next
您可以进一步整理/改进此代码,因为 arrFileList(0)
完成后将没有任何价值。