首页 > 解决方案 > FileSystemObject.FolderExists 被文件名中的空格破坏

问题描述

我有一个目录,其路径包含空格 ( C:\foo bar\)。目录存在。

我可以打开命令提示符并执行以下操作:

cd "C:\foo bar\"

我的当前目录按预期更改为该目录。

在 VBS 中,我这样做:

Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")

Dim path: path = "C:\foo bar\"

If Not fso.FolderExists(Chr(34) & path & Chr(34)) Then
    MsgBox "escaped path doesn't exist"
End If

If Not fso.FolderExists(path) Then
    MsgBox "unquoted it's still not found!"
End If

...并且我在脚本运行时看到了弹出对话框,但不应该。

它似乎也导致该MoveFile功能出现问题。

这个 VBS 脚本是由 VB6 服务执行的,所以我不能选择用更现代的方式来编写它。

标签: vbscriptfilesystemobject

解决方案


推荐阅读