检查目录是否存在,但对该目录没有权限



我使用以下代码让用户提供SFTP目录的路径,以便记录在此类供应商项目的清单中。我在为一个我知道目录存在的项目填充路径时遇到了一个问题,所以我99%确信问题是我没有访问该目录的权限(我知道我没有(。

'Check if the SFTP exists already
If MsgBox("Does the SFTP for this vendor/campaign already exist?", vbYesNo, "SFTP Exists?") = vbYes Then
'Prompt for the network folder
Do While SFTP = ""
SFTP = Trim(InputBox("Please provide the folder path to the report's SFTP.", "New Campaign/Vendor SFTP", " "))

Select Case SFTP
Case "", " "
If MsgBox("No path provided for the new campagin/vendor SFTP folder. Would you like to retry providing the SFTP (clicking 'No' " & _
"will leave the SFTP folder field empty for now).", vbYesNo, "No Value Provided") = vbNo Then
SFTP = "ignore"
Else
SFTP = ""
End If

Case Else
'Potentially valid folder, check if it exists already
If Dir(SFTP, vbDirectory) = "" Then
'Provided path doesn't exist, prompt user to retry
If MsgBox("The specified path (" & SFTP & ") does not exist. Would you like to retry providing the SFTP (clicking 'No' " & _
"will leave the SFTP folder field empty for now).", vbYesNo, "Create the Folder?") = vbYes Then
SFTP = ""
Else
SFTP = "ignore"
End If
End If 'the folder exists no action needed

End Select
Loop
Else
'Set SFTP to ignore so that we leave the field blank downstream
SFTP = "ignore"
End If

特别是,我得到了运行时错误52。

有没有一种方法可以使用DIR或类似的方法来检查目录是否存在,而不需要对文件夹的权限

我想保留这种验证,以避免打字错误扰乱库存表(在路径的后面是用来在表中创建链接的,坏的路径显然会弄乱(,但我不能总是确定填写路径的人是否有权访问文件夹。

引用"Microsoft脚本运行时。。

不确定。。检查这是否有效。。。

Dim fso As Scripting.FileSystemObject
Set fso = New Scripting.FileSystemObject

然后可以使用..检查文件夹是否存在。。

If fso.FolderExists(FolderPathHere ending with ) Then

相关内容

  • 没有找到相关文章

最新更新