如果VB中的文件夹不存在,如何创建它?
我自己编写了一个小下载应用程序,这样我就可以轻松地从我的服务器获取一组文件,并将它们全部放到一台全新安装了 Windows 的新电脑上,而无需实际上网。 不幸的是,我在创建要放入它们的文件夹时遇到问题,并且不确定如何进行。
我希望我的程序将应用程序下载到 program files\any name here\
所以基本上我需要一个函数来检查文件夹是否存在,如果不存在则创建它。
I wrote myself a little downloading application so that I could easily grab a set of files from my server and put them all onto a new pc with a clean install of Windows, without actually going on the net. Unfortunately I'm having problems creating the folder I want to put them in and am unsure how to go about it.
I want my program to download the apps to program files\any name here\
So basically I need a function that checks if a folder exists, and if it doesn't it creates it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
只需这样做:
我将文件夹路径声明为字符串(sPath),这样,如果您多次使用它,则可以轻松更改它,但也可以通过程序本身进行更改。
希望能帮助到你!
-nfell2009
Just do this:
I declared the folder path as a String (sPath) so that way if you do use it multiple times it can be changed easily but also it can be changed through the program itself.
Hope it helps!
-nfell2009
(导入System.IO)
(imports System.IO)
您应该尝试使用文件系统对象或 FSO。 有许多属于该对象的方法可以检查文件夹是否存在以及创建新文件夹。
You should try using the File System Object or FSO. There are many methods belonging to this object that check if folders exist as well as creating new folders.
我了解这是如何工作的,创建一个允许用户命名文件夹并将其放置在您想要的位置的对话框的过程是什么。
干杯
I see how this would work, what would be the process to create a dialog box that allows the user name the folder and place it where you want to.
Cheers
试试这个:
Directory.Exists(TheFolderName)
和Directory.CreateDirectory(TheFolderName)
(您可能需要:
Imports System.IO
)Try this:
Directory.Exists(TheFolderName)
andDirectory.CreateDirectory(TheFolderName)
(You may need:
Imports System.IO
)VB.NET? System.IO.Directory.Exists(字符串路径)
VB.NET? System.IO.Directory.Exists(string path)
Directory.CreateDirectory() 应该这样做。
http://msdn.microsoft .com/en-us/library/system.io.directory.createdirectory(VS.71).aspx
另外,在 Vista 中,您可能无法直接写入 C: ,除非您以管理员身份运行它,所以您可能只是想绕过它并在 C: 的子目录中创建你想要的目录(我想说这是一个应该遵循的好习惯。--令人难以置信的是有多少人只是将垃圾倾倒到 C:
希望有帮助。
Directory.CreateDirectory() should do it.
http://msdn.microsoft.com/en-us/library/system.io.directory.createdirectory(VS.71).aspx
Also, in Vista, you probably cannot write into C: directly unless you run it as an admin, so you might just want to bypass that and create the dir you want in a sub-dir of C: (which i'd say is a good practice to be followed anyways. -- its unbelievable how many people just dump crap onto C:
Hope that helps.
在System.IO下,有一个名为Directory的类。
执行以下操作:
它将确保该目录存在。
Under System.IO, there is a class called Directory.
Do the following:
It will ensure that the directory is there.
尝试使用 System.IO.DirectoryInfo 类。
来自MSDN的示例:
Try the System.IO.DirectoryInfo class.
The sample from MSDN:
由于问题没有指定 .NET,因此这应该适用于 VBScript 或 VB6。
Since the question didn't specify .NET, this should work in VBScript or VB6.