Re: Tool for deleting all files except specific file extension?
de Steven Burn 06/07/2006 12:44
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!
<laterna@magic.ms> wrote in message
news:1149629424.999143.324520@c74g2000cwc.googlegroups.com...
> 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
>