kill

ADO DOT NET

Well-known member
Joined
Dec 20, 2006
Messages
156
Kill(My.Application.Info.DirectoryPath & "\*.txt")

I am deleting all text files with the above command.
but if there is no file I will get an error
I want to check first, and if theres at least one file with .txt ext. then run that command.
but dont know how to check if there is a file with a specific ext. ?
the name maybe anything...
 
It simply returns an error:
Code:
System.IO.Directory.GetFiles("c:\*.txt")
I want to check if there is at least one .txt file in the specified path, possible?
 
Code:
        If Directory.GetFiles(My.Application.Info.DirectoryPath, "*.txt") IsNot Nothing Then
            ...
        End If
Always occurs! :confused:
 
That will not work because even if there are no files matching the pattern, the method will still return an array (an empty one). Check the size of the returned array, if it is 0 then there are no files that match the requirement, if > 0 then you got some files.
 
Could you use:

[VB]
If File.Exists (My.Application.DirectoryPath, "*.txt") then
File.Delete
End If
[/VB]

or

[VB]
Do While File.Exists (My.Application.DirectoryPath, "*.txt") = True
File.Delete
Loop
[/VB]
 
Back
Top