VB.NET Delete all file extensions in folder.

Posted on 2006-06-02
Last Modified: 2011-08-18
Does anyone know code that would delete all files in a folder when all you know is the file extension?

This doesn't work.

Dim path As String = "C:\TEMP\*.WCH"

        Catch ex As Exception
        End Try

I get an error about 'invalid characters'.  I also tried Dim path As String = "C:\TEMP\%.WCH".  That didn't throuw an error, but it didn't delete the file either.


Question by:mikodmc
    LVL 12

    Accepted Solution

          Dim d As New IO.DirectoryInfo("c:\temp\")
            Dim f As IO.FileInfo
            For Each f In d.GetFiles("*.wch")
                io.file.delete (f..FullName)
    LVL 5

    Expert Comment

    what jonas said is right.

    iterate on Directory.getFiles("*.wch")
    then call delete in your for each


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now