Dim objShell, objFSO, objFolder, objFile, strPath, arrFiles, intIndex
' 设置要操作的文件夹路径
strPath = "C:\Users\YourUsername\Desktop"
' 创建FileSystemObject对象
Set objFSO = CreateObject("Scripting.FileSystemObject")
' 获取文件夹对象
Set objFolder = objFSO.GetFolder(strPath)
' 获取文件夹中的文件列表
arrFiles = Array()
For Each objFile In objFolder.Files
arrFiles = Array(objFile.Name)
Next
' 初始化索引
intIndex = 0
' 显示第一个文件名
WScript.Echo arrFiles(intIndex)
' 等待用户按键
Do While True
On Error Resume Next
WScript.Sleep 100
Dim strKey
strKey = WScript.StdIn.Read(1)
If Err.Number <> 0 Then
Err.Clear
strKey = ""
End If
On Error GoTo 0
' 根据按键调整索引
Select Case strKey
Case "{UP}"
If intIndex > 0 Then intIndex = intIndex - 1
Case "{DOWN}"
If intIndex < UBound(arrFiles) Then intIndex = intIndex + 1
Case "+"
Exit Do
End Select
' 显示当前选中的文件名
WScript.Echo arrFiles(intIndex)
Loop
' 释放对象
Set objFile = Nothing
Set objFolder = Nothing
Set objFSO = Nothing