3
Contributors
11
Replies
19
Views
8 Years
Discussion Span
Last Post by sknake
0
Private Sub RemoveDir(ByVal _path As String)
        For Each mDir As String In IO.Directory.GetDirectories(_path)
            My.Computer.FileSystem.DeleteDirectory(mDir, FileIO.DeleteDirectoryOption.DeleteAllContents)
        Next
    End Sub

if the given path has no content then ofc not get deleted

0
Private Sub RemoveDir(ByVal _path As String)
        For Each mDir As String In IO.Directory.GetDirectories(_path)
            My.Computer.FileSystem.DeleteDirectory(mDir, FileIO.DeleteDirectoryOption.DeleteAllContents)
        Next
    End Sub

if the given path has no content then ofc not get deleted

i want to delete files if files exist in directory

0

so now im confused....
what exactlly you want? just empty a directory without removing the directory? but then i dont understand why you wanna check if a file exist if u dont know the name o.O

0
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
		Dim strDir As String = "C:\testdir\"
		If (System.IO.Directory.Exists(strDir)) Then
			Dim dir As New System.IO.DirectoryInfo("C:\testdir")
			Dim files As System.IO.FileInfo() = dir.GetFiles()
			For Each file As System.IO.FileInfo In files
				System.IO.File.Delete(file.FullName)
			Next
		End If
	End Sub
0

when a file is uploaded by a user it is stored in a folder.. if he uploades other file in the same folder, the file which was already uploaded by him should be deleted and newly uploaded file must be saved.
files are uploaded by users.. so we dnt know the filename..

0

if System.IO.File.Exists("fileName") then System.IO.File.Delete("fileName") then save the new file just like you did before when it didn't exist.

0

You're welcome

Please mark this thread as solved if you have found the answer to your original question and good luck!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.