Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • Leaders
Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...