ADO DOT NET Posted June 9, 2007 Posted June 9, 2007 Hi, I want to check if there is any text file in the application path, then delete all of them. So I use this code: If System.IO.Directory.GetFiles(My.Application.Info.DirectoryPath, "*.txt").Length > 0 Then My.Computer.FileSystem.DeleteFile(My.Application.Info.DirectoryPath + "\*.txt") End If But I get error: A first chance exception of type 'System.ArgumentException' occurred in mscorlib.dll Quote
Leaders dynamic_sysop Posted June 10, 2007 Leaders Posted June 10, 2007 you are trying to delete the path name with \*.txt attached to the end of it there, not the actuall files, also you need to delete them 1 by 1 it can be done easily like this... For Each f As String In System.IO.Directory.GetFiles(My.Application.Info.DirectoryPath, "*.txt") My.Computer.FileSystem.DeleteFile(f) Next Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.