Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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 there's at least one file with .txt ext. then run that command.

but don't know how to check if there is a file with a specific ext. ?

the name maybe anything...

  • *Experts*
Posted
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.
Posted

Could you use:

 

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

 

or

 

Do While File.Exists (My.Application.DirectoryPath, "*.txt") = True
    File.Delete
Loop

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

-- Rick Cook, The Wizardry Compiled

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...