[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VB.NET Delete all file extensions in folder.

Posted on 2006-06-02
3
Medium Priority
?
708 Views
Last Modified: 2011-08-18
Hi,
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"

        Try
            File.Delete(path)
        Catch ex As Exception
            MsgBox(ex.ToString)
        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.

Thanks,
Dan

0
Comment
Question by:mikodmc
2 Comments
 
LVL 12

Accepted Solution

by:
vb_jonas earned 500 total points
ID: 16819505
      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)
        Next
0
 
LVL 5

Expert Comment

by:mydasx
ID: 16821119
what jonas said is right.

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

mydasx
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month17 days, 21 hours left to enroll

829 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