我给自己写了一个小的下载应用程序,这样我就可以轻松地从我的服务器中获取一组文件,并将它们全部放到一台干净安装Windows的新电脑上,而无需实际上网.不幸的是我在创建我想要放入的文件夹时遇到问题,我不确定如何去做.
我希望我的程序能够下载应用程序 program files\any name here\
所以基本上我需要一个函数来检查文件夹是否存在,如果不存在则创建它.
If(Not System.IO.Directory.Exists(YourPath)) Then System.IO.Directory.CreateDirectory(YourPath) End If
在System.IO下,有一个名为Directory的类.请执行下列操作:
If Not Directory.Exists(path) Then Directory.CreateDirectory(path) End If
它将确保目录在那里.
由于问题没有指定.NET,因此这应该适用于VBScript或VB6.
Dim objFSO, strFolder strFolder = "C:\Temp" Set objFSO = CreateObject("Scripting.FileSystemObject") If Not objFSO.FolderExists(strFolder) Then objFSO.CreateFolder(strFolder) End If
试试System.IO.DirectoryInfo类.
来自MSDN的示例:
Imports System Imports System.IO Public Class Test Public Shared Sub Main() ' Specify the directories you want to manipulate. Dim di As DirectoryInfo = New DirectoryInfo("c:\MyDir") Try ' Determine whether the directory exists. If di.Exists Then ' Indicate that it already exists. Console.WriteLine("That path exists already.") Return End If ' Try to create the directory. di.Create() Console.WriteLine("The directory was created successfully.") ' Delete the directory. di.Delete() Console.WriteLine("The directory was deleted successfully.") Catch e As Exception Console.WriteLine("The process failed: {0}", e.ToString()) End Try End Sub End Class
试试这个:Directory.Exists(TheFolderName)
和Directory.CreateDirectory(TheFolderName)
(您可能需要:Imports System.IO
)
VB.NET?System.IO.Directory.Exists(字符串路径)