Tool for deleting all files except specific file extension?

  • Thread starter Thread starter laterna
  • Start date Start date
L

laterna

Hello,

I have a folder containing many subfolders.
Within all this subfolders there are a lot of files having
different file extensions ( .zip, .jpg, .txt, .doc, .xls, ...)

I want to delete all files in all subfolders except one or
more specific file extension.

For example, I want to delete all files in all subfolders
except all .zip and .jpg files.

Do you know a tool (running on Windows XP) which can do this job?

Many thanks for any hint.

Regards

Hans
 
If you don't mind scripts, then this will do it for you.....

'// BEGIN SCRIPT
'// Filename: vbsDelExt.vbs
'//
'// Purpose: Delete files without deleting specific extensions
'// Requires: WSH 5.6 or newer
'// Input required: Extensions to keep, in the format ext1;ext2;ext3 etc etc
'//
Option Explicit

'// BEGIN This should be all on one line
Dim strFiletype: strFileType = InputBox("Enter the extensions to keep or
leave blank to delete all" & vbCrLf & vbCrLf & "NOTE: Files deleted via this
script will only be recoverable using recovery programs such as
Restoration")
'// END This ^^^^^ should be all on one line

'// We don't need periods
strFileType = Replace(strFileType, ".", "")
'// Prevent error
If Len(strFileType) < 1 Then strFileType = "NULL"
'// Kill the files, beginning with the current directory
RunDelete(".\")
WScript.Echo "Finished"
Sub RunDelete(sWhere)
Dim objFSO, objFldr, objSFldr, objFile, strTemp
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFldr = objFSO.GetFolder(sWhere)
'// Loop through the files
For Each objFile In objFldr.Files
'// Don't kill our script
If objFile.Name <> "vbsDelExt.vbs" Then
Select Case strFileType
'// If no extensions were specified, kill them all
Case "NULL": objFSO.DeleteFile objFile
'// If extensions were specified, keep the ones the user
wants to keep
Case Else
Dim sTemp
sTemp = Split(objFile.Name, ".")(1)
WScript.Echo "[DEBUG] InStrRev: " & sTemp & " - " &
InStrRev(LCase(strFileType),LCase(sTemp))
If NOT InStrRev(LCase(strFileType),LCase(sTemp)) > 0 Then
objFSO.DeleteFile objFile.Path
End Select
End If
Next
'// Recursion
For Each objSFldr In objFldr.SubFolders
Call RunDelete(objSFldr.Path)
Next
Set objFSO = Nothing
End Sub
'// END SCRIPT

Downloadable copy can be found at;

http://downloads.mysteryfcm.co.uk/?f=Scripts

Filename: vbsDelExt.vbs

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
 
leave blank to delete all" & vbCrLf & vbCrLf & "NOTE: Files deleted via this
script will only be recoverable using recovery programs such as
Restoration")

I don't know whether VBScript can do it, but FSO can be told to use
the Recycle bin.
 
Al Klein said:
I don't know whether VBScript can do it, but FSO can be told to use
the Recycle bin.

I know .... just couldn't be bothered to put it in ;o) (way too much hassle
for a simple script)

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
 
On 6 Jun 2006 14:30:25 -0700, (e-mail address removed) wrote:

I want to delete all files in all subfolders except one or
more specific file extension.

< snip >

Do a search for all files eg. *.* .

Sort by extension.

Select all.

De-select the extension(s) you want to keep.

Delete.

Regards, John.

--
****************************************************
,-._|\ (A.C.F FAQ) http://clients.net2000.com.au/~johnf/faq.html
/ Oz \ John Fitzsimons - Melbourne, Australia.
\_,--.x/ http://www.vicnet.net.au/~johnf/welcome.htm
v http://clients.net2000.com.au/~johnf/
 
I have a folder containing many subfolders.
Within all this subfolders there are a lot of files having
different file extensions ( .zip, .jpg, .txt, .doc, .xls, ...)

I want to delete all files in all subfolders except one or
more specific file extension.

Install Cygwin and learn some bash scripting, it's the most flexible
solution for problems like these.

Regards,
wwwald
 
Rich_on 6-Jun-2006 said:
I have a folder containing many subfolders.
Within all this subfolders there are a lot of files having
different file extensions ( .zip, .jpg, .txt, .doc, .xls, ...)

I want to delete all files in all subfolders except one or
more specific file extension.

For example, I want to delete all files in all subfolders
except all .zip and .jpg files.

Do you know a tool (running on Windows XP) which can do this job?

eXtreme Advanced File Manager
http://homepages.paradise.net.nz/link

No need to bother with scripts or batch files, extreame is an XTree clone
which makes file management, IMHO easy.
Anyone who used Xtree in the days of DOS or now uses ZTree will have no
problem.
You can use a mouse (nasty clicky thing) but much easier to use the
keyboard.
For the above senario

select your disk drive
press G to go global
press F to make a file mask - in this case *.txt - only the txt files a
shown
press ctrl-T to tag all of them
press F *.* to revert back to all files
press ctrl-I to invert the tags - everything except txt files are now tagged
press ctrl-D to delete all the tagged files.

OK - I know a batch file once written can be run with the click of a button
as often as you want but a good file manager is much more flexible.
I use Ztree (payware) all the time and would be lost without it.

extreame is now up to version 5 , which must be a recent update as I am
still using v.4.2 - tiny download - 177kb.
There is a link on the site to 'using the original xtree' which is worth a
look.
 
Hello,

I have a folder containing many subfolders.
Within all this subfolders there are a lot of files having
different file extensions ( .zip, .jpg, .txt, .doc, .xls, ...)

I want to delete all files in all subfolders except one or
more specific file extension.

For example, I want to delete all files in all subfolders
except all .zip and .jpg files.

Do you know a tool (running on Windows XP) which can do this job?

Many thanks for any hint.

Regards

Hans

Well you could use xxcopy -

xxcopy /rs /s /x*.zip /x*.jpg *.*
 
John Hood said:
Sorry, FSO?

Vas ist?

FSO = FileSystemObject

Part of the MS Windows Scripting Runtime (WSR) and is encompassed in the
scrrun.dll AX (ActiveX) file. Tis used for file/folder creation, deletion
and manipulation. Though most app's will use the API's (Application
Programming Interface) to do this, VBScript cannot, so uses the FSO instead.

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
 
Steven said:
FSO = FileSystemObject

Part of the MS Windows Scripting Runtime (WSR) and is encompassed in the
scrrun.dll AX (ActiveX) file. Tis used for file/folder creation, deletion
and manipulation. Though most app's will use the API's (Application
Programming Interface) to do this, VBScript cannot, so uses the FSO instead.
Gotcha, Thank you.

John H.
 
Back
Top