首页 > 解决方案 > vbs 脚本在桌面上显示文件和文件夹,但这没有运行并引发错误

问题描述

Set fso=CreateObject("Scripting.FileSystemObject")
DesktopPath=CreateObject("WScript.Shell").SpecialFolders("Desktop")
'Files count
msgbox "the no of files on the desktop is:"
&fso.GetFolder(DesktopPath).Files.count
'Folders count
msgbox "the no of folder on the desktop is:"
&fso.GetFolder(DesktopPath).SubFolders.count

上述代码显示以下错误

标签: vbscript

解决方案


您应该在for break a line_的注释末尾添加:MsgBox

Set fso=CreateObject("Scripting.FileSystemObject")
DesktopPath=CreateObject("WScript.Shell").SpecialFolders("Desktop")
'Files count
msgbox "The N° of files on the desktop is : "_
& fso.GetFolder(DesktopPath).Files.count
'Folders count
msgbox "The N° of folder on the desktop is : "_
& fso.GetFolder(DesktopPath).SubFolders.count

推荐阅读