日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

vb在服务器上新建文件夹,vb.net-如果不存在,如何在VB中创建文件夹?

發布時間:2023/12/1 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 vb在服务器上新建文件夹,vb.net-如果不存在,如何在VB中创建文件夹? 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

vb.net-如果不存在,如何在VB中創建文件夾?

我為自己編寫了一個小小的下載應用程序,以便我可以輕松地從服務器上獲取一組文件,然后將它們全部放入帶有全新安裝的Windows的新PC上,而無需實際運行網絡。 不幸的是,我在創建要放入的文件夾時遇到了問題,不確定如何處理。

我希望我的程序將應用程序下載到program files\any name here\

因此,基本上我需要一個函數來檢查文件夾是否存在,如果不存在,它將創建該文件夾。

12個解決方案

149 votes

If(Not System.IO.Directory.Exists(YourPath)) Then

System.IO.Directory.CreateDirectory(YourPath)

End If

Quintin Robinson answered 2020-01-27T14:28:41Z

22 votes

在System.IO下,有一個名為Directory的類。請執行下列操作:

If Not Directory.Exists(path) Then

Directory.CreateDirectory(path)

End If

這將確保該目錄在那里。

MagicKat answered 2020-01-27T14:29:05Z

11 votes

由于問題未指定.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

Rick answered 2020-01-27T14:29:25Z

10 votes

試試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

Guy Starbuck answered 2020-01-27T14:29:49Z

5 votes

VB.NET? System.IO.Directory.Exists(字符串路徑)

Chris Bilson answered 2020-01-27T14:30:09Z

5 votes

試試這個:Imports System.IO和Directory.CreateDirectory(TheFolderName)

(您可能需要:Imports System.IO)

GEOCHET answered 2020-01-27T14:30:33Z

4 votes

Directory.CreateDirectory()應該這樣做。[http://msdn.microsoft.com/zh-cn/library/system.io.directory.createdirectory(VS.71).aspx]

另外,在Vista中,除非您以管理員身份運行它,否則您可能無法直接寫入C :,所以您可能只想繞過它,并在C:的子目錄中創建所需的目錄(我想說的是 無論如何都要遵循的一個好習慣-令人難以置信的是有多少人將廢話扔到C上:

希望能有所幫助。

Mostlyharmless answered 2020-01-27T14:31:04Z

4 votes

(導入System.IO)

if Not Directory.Exists(Path) then

Directory.CreateDirectory(Path)

end if

Wayne answered 2020-01-27T14:31:23Z

3 votes

If Not Directory.Exists(somePath) then

Directory.CreateDirectory(somePath)

End If

Siddharth Rout answered 2020-01-27T14:31:39Z

1 votes

您應該嘗試使用文件系統對象或FSO。 屬于該對象的方法有很多,它們可以檢查文件夾是否存在以及創建新文件夾。

Dave answered 2020-01-27T14:31:59Z

0 votes

我知道它是如何工作的,創建對話框的過程將是什么,該對話框允許用戶命名文件夾并將其放置在所需的位置。

干杯

answered 2020-01-27T14:32:24Z

0 votes

只是這樣做:

Dim sPath As String = "Folder path here"

If (My.Computer.FileSystem.DirectoryExists(sPath) = False) Then

My.Computer.FileSystem.CreateDirectory(sPath + "/")

Else

'Something else happens, because the folder exists

End If

我將文件夾路徑聲明為String(sPath),這樣,如果您多次使用它,則可以輕松更改它,也可以通過程序本身對其進行更改。

希望能幫助到你!

-nfell2009

BaeFell answered 2020-01-27T14:32:57Z

總結

以上是生活随笔為你收集整理的vb在服务器上新建文件夹,vb.net-如果不存在,如何在VB中创建文件夹?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。