2017-09-27 18 views
0

名前がtempのディレクトリがあります。さまざまな名前のさまざまなフォルダが含まれています。私はテストのような特定の名前のフォルダを削除したい。 vb.netでそれを削除する方法。私を助けてください。パスからフォルダ名を取得

+0

ようこそ!このサイトはコード作成サービスではありません(あなたはたまに運があります)。 [ツアー](http://stackoverflow.com/tour)、[ヘルプセンター](http://stackoverflow.com/help)、[良い質問をする方法](http://このサイトがどのように機能するかを確認し、現在および将来の質問を改善するのに役立ち、より良い回答を得るのに役立ちます。 –

答えて

0

は、次のコードでは注意してくださいとあなたのニーズに合わせてコードを編集:スタックオーバーフローへ

Imports System.IO 

Public Class Form1 
    Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click 
    Dim directoryName As String = "D:\_working" 
    Dim subPath = directoryName & "\TEST" '// be careful - subPath will be deleted! 

    Try 
     Dim directoryExists = Directory.Exists("D:\_working") 
     Dim subDirectoryExists = Directory.Exists(subPath) 

     MessageBox.Show("top-level directory exists: " & directoryExists) 
     MessageBox.Show("sub-directory exists: " & subDirectoryExists) 

     For Each deleteFile In Directory.GetFiles(subPath, "*.BMP", SearchOption.TopDirectoryOnly) 
     File.Delete(deleteFile) 
     '// you may want to log all deleted files here ... 
     Next 

     Directory.Delete(subPath) '// without the need of logging add ..(subPath, true) 

    Catch ex As Exception 
     MessageBox.Show("The process failed: {0}", ex.Message) 
    End Try 

    End Sub 
End Class 
+2

すべてのファイルを反復する代わりに、[** 'Directory.Delete(subPath、True)' **](https://msdn.microsoft.com/en-us/library/fxeahc5f(v=vs.110) ).aspx)。 –

0

はあなたImports System.IO

は、あなただけのパスがパスの値に等しい文字列であり、この

File.Delete(path) 

を行うことができていることを確認します。

関連する問題