检查目录是否存在Visual Basic(System.IO.Directory不起作用)

时间:2019-04-15 16:34:47

标签: .net vbscript

调用此方法时,它仅返回错误,系统变量未定义。

我当前正在尝试制作GPO登录脚本,以检查目录是否存在以及是否不创建目录。

我非常困惑,因为有太多的视觉基本变体,而且我似乎找不到我需要的东西。我需要的视觉基础是vbs或vb.net还是即时失去的vb脚本。

System.IO.Directory仅返回一个错误,我尝试了许多其他操作,但收到相同的错误。

Option Explicit
Dim l: l = "Z:"
Dim s: s = "\\TEST-SERVER\Shared Folder"
Dim Network: Set Network = CreateObject("WScript.Network")
Dim CheckDrive: Set CheckDrive = Network.EnumNetworkDrives()
Dim DriveExists: DriveExists = False
Dim i
'check to see if drive exists
For i = 0 to CheckDrive.Count - 1
  If CheckDrive.Item(i) = l Then
    DriveExists = True
  End If
Next
'if drive doesnt map it
If DriveExists = False Then
  Network.MapNetworkDrive l, s, False
Else
 'drive already mapped
End If


Dim strDirectory 
strDirectory = "C:\Screensaver"
If(Not System.IO.Directory.Exists(strDirectory)) Then
    System.IO.Directory.CreateDirectory(strDirectory)
End If

1 个答案:

答案 0 :(得分:0)

System。*用于VB.net,但是脚本的其余部分看起来像是VBS。 VBS可以使用FileSystemObject与文件夹进行交互。

在尝试创建目录的部分尝试以下操作:

skip=n-1
相关问题