|
-
Feb 12th, 2010, 11:34 AM
#1
Thread Starter
Lively Member
[RESOLVED] How to delete multiple file extension
I want to delete multiple file extensions like txt, vbs how to do that.
My.Computer.FileSystem.DeleteFile
don't allow me to delete multiple files
< advertising link removed by moderator >
-
Feb 12th, 2010, 11:40 AM
#2
Re: How to delete multiple file extension
Try something like this:
Code:
Dim ExtToFind() As String = {"*.txt", "*.vbs"}
Dim FilesToDelete = My.Computer.FileSystem.GetFiles("C:\somedirectory\", FileIO.SearchOption.SearchAllSubDirectories, ExtToFind)
For Each FileName As String In FilesToDelete
My.Computer.FileSystem.DeleteFile(FileName)
Next
-
Feb 12th, 2010, 11:41 AM
#3
Re: How to delete multiple file extension
put he extensions in to an array and loop through the array calling directory.getfiles using the current array element as the filter
Code:
Dim exts() as string = {"*.txt", "*.vbs"}
Dim folder as string = "put the directory path where you want to delete files here"
Try
For Each ext as string In file exts
For Each f as string In system.io.directory.getfiles(folder, ext)
system.io.file.delete(f)
next
next
Catch ex as exception
messagebox.show(ex.message)
end try
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Feb 12th, 2010, 11:43 AM
#4
Re: How to delete multiple file extension
Edit: Kleinma beats me
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Feb 12th, 2010, 12:08 PM
#5
Thread Starter
Lively Member
Re: How to delete multiple file extension
Thanks Kleinma that worked
But is there a way that i can delete multiple file by doing recursive search
ie I want to scan all folder and subfolder.
Last edited by riteshtechie; Feb 12th, 2010 at 12:17 PM.
< advertising link removed by moderator >
-
Feb 12th, 2010, 12:30 PM
#6
Re: [RESOLVED] How to delete multiple file extension
That is exactly what my code does.
Notice the param passed to the GetFiles method that uses the value of SearchAllSubDirectories. That means it will search the directory you specify, and all sub directories under it.
Just note if you do something like specify C:\ as your directory and tell it to scan all subdirectories, it is going to recurse the entire file system and will take a while.
-
Feb 12th, 2010, 01:00 PM
#7
Thread Starter
Lively Member
Re: [RESOLVED] How to delete multiple file extension
Yeah oops sorry I did a typo and thought somethings wrong with the code thanks for help.
How Can I add WIndows folder to "C:\Somedirectory"
This code is not working
Dim FilesToDelete = My.Computer.FileSystem.GetFiles(Environ("%systemdrive"), FileIO.SearchOption.SearchAllSubDirectories, ExtToFind)
< advertising link removed by moderator >
-
Feb 12th, 2010, 01:03 PM
#8
Re: [RESOLVED] How to delete multiple file extension
systemdrive is going to give you the root letter of the drive windows is installed on.
You don't include % when accessing them through the environ method.
So it would just be Environ("systemdrive") which in most cases will return "C:"
-
Feb 12th, 2010, 01:04 PM
#9
Thread Starter
Lively Member
Re: [RESOLVED] How to delete multiple file extension
Great thanks.
Thanks a million.
< advertising link removed by moderator >
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|