检查Dir是否存在Visual Basic(System.IO.Directory不工作)

问题描述 投票:0回答:1

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

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

我很困惑,因为有很多视觉基本变体,我似乎无法找到我需要的东西。是视觉基础我需要vbs或vb.net或vb scrips我老实说丢了。

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
.net vbscript
1个回答
0
投票

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

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

Dim strDirectory
strDirectory = "C:\Screensaver"
Set fso = CreateObject("Scripting.FileSystemObject")
If(Not fso.FolderExists(strDirectory)) Then
    fso.CreateFolder(strDirectory)
End If
© www.soinside.com 2019 - 2024. All rights reserved.