在Text1里有一個(gè)絕對(duì)路徑,判斷是否存在這個(gè)文件夾。
讓客戶(hù)滿(mǎn)意是我們工作的目標(biāo),不斷超越客戶(hù)的期望值來(lái)自于我們對(duì)這個(gè)行業(yè)的熱愛(ài)。我們立志把好的技術(shù)通過(guò)有效、簡(jiǎn)單的方式提供給客戶(hù),將通過(guò)不懈努力成為客戶(hù)在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:域名注冊(cè)、網(wǎng)站空間、營(yíng)銷(xiāo)軟件、網(wǎng)站建設(shè)、海門(mén)網(wǎng)站維護(hù)、網(wǎng)站推廣。
存在則彈出對(duì)話(huà)框:文件已存在;不存在則依照路徑新建文件夾并彈出對(duì)話(huà)框:創(chuàng)建完畢!
舉個(gè)例子:
先引入命名空間:
Imports
System.IOImports
System.Security.AccessControl
代碼:
Dim
sec
As
DirectorySecurity
=
New
DirectorySecurityDim
rule
As
FileSystemAccessRule
=
New
FileSystemAccessRule("Administrator",
FileSystemRights.Delete,
AccessControlType.Allow)sec.AddAccessRule(rule)Directory.CreateDirectory("C:\test",
sec)
這段代碼就是以
Administrator
帳戶(hù)
在
C:\
創(chuàng)建
test
文件夾。
Private Sub btnRemovePath_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemovePath.Click
Try
' 先建立目錄以便用于后續(xù)的刪除示范。
If Not Directory.Exists("D:\網(wǎng)易") Then
Directory.CreateDirectory(" D:\網(wǎng)易 \Test1")
Directory.CreateDirectory(" D:\網(wǎng)易 \Test2")
Directory.CreateDirectory(" D:\網(wǎng)易 \Test3")
End If
' 刪除子目錄 Test1。
Directory.Delete(" D:\網(wǎng)易 \Test1", True)
' 刪除子目錄 Test2。
Dim myDirectoryInfo As New DirectoryInfo(" D:\網(wǎng)易 \Test2")
myDirectoryInfo.Delete(True)
' 將目錄 C:\AlexDirDemo 及其以下的文件和子目錄全數(shù)刪除。
Directory.Delete(" D:\網(wǎng)易 ", True)
Catch ex As Exception
MessageBox.Show(ex.Message)
Exit Sub
End Try
' 啟動(dòng) Windows 資源管理器。
Process.Start("explorer.exe", "D:\")
End Sub
用Directory.CreateDirectory即可創(chuàng)建文件夾:
'?建立目錄
If?Not?Directory.Exists("C:\負(fù)屃\"??TextBox1.Text)?Then?'檢查文件夾是否存在
Directory.CreateDirectory("C:\負(fù)屃\"??TextBox1.Text)??'不存在,創(chuàng)建文件建夾
End?If
你的例子是因?yàn)樯倭艘粋€(gè)"\"引起的,正確的如下:
Dim?fsotest?As?New?FileSystemObject
If?fsotest.FileExists("C:\負(fù)屃\"??TextBox1.Text)?=?False?Then
fsotest.CreateFolder("C:\負(fù)屃\"??TextBox1.Text) '這里你少了一個(gè)\
End?If
MsgBox("創(chuàng)建成功")
分享題目:vb.net創(chuàng)建新文件夾,VB創(chuàng)建文件夾
轉(zhuǎn)載來(lái)于:http://chinadenli.net/article32/heigpc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作、網(wǎng)站建設(shè)、定制開(kāi)發(fā)、虛擬主機(jī)、服務(wù)器托管、全網(wǎng)營(yíng)銷(xiāo)推廣
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
移動(dòng)網(wǎng)站建設(shè)知識(shí)