[windows2000] Re: Delete Utility

  • From: "Costanzo, Ray" <RCostanzo@xxxxxxxxxxxxxxxxxxxxx>
  • To: <windows2000@xxxxxxxxxxxxx>
  • Date: Thu, 9 Nov 2006 09:05:54 -0500

Oops!  The easy fix:
 
delzips.vbs:

Option Explicit

 

Const ROOT_PATH = "R:\temp" 
Const NO_DELETE = "nodeldir"  ''name of directory to keep
Dim oFSO

 

Call Main()

 

Sub Main
 Set oFSO = CreateObject("Scripting.FileSystemObject")
 Call Delzips(oFSO.GetFolder(ROOT_PATH))
End Sub

 

Sub Delzips(dir)
 Dim oSubdir, oFile
 For Each oSubdir in dir.Subfolders
  Call Delzips(oSubdir)
 Next
 
 If dir.Name <> NO_DELETE Then 

  On Error Resume Next
  'oFSO.DeleteFile(oFSO.BuildPath(dir.Path, "*.zip"))

   On Error Goto 0
  WScript.Echo "Would delete " & oFSO.BuildPath(dir.Path, "*.zip")
 End If
End Sub

 

Ray at work

        -----Original Message-----
        From: windows2000-bounce@xxxxxxxxxxxxx
[mailto:windows2000-bounce@xxxxxxxxxxxxx] On Behalf Of Steve Rance
        Sent: Thursday, November 09, 2006 9:03 AM
        To: windows2000@xxxxxxxxxxxxx
        Subject: [windows2000] Re: Delete Utility
        
        

        Ray,

         

        Wow thanks for that...it works on my test data too except if
there is not a zip file in the directory it crashes out with a "File not
found" error message.  Not sure how to fix it.

        Thanks again Ray!!!

         

        Steve

         

        
________________________________


        From: windows2000-bounce@xxxxxxxxxxxxx
[mailto:windows2000-bounce@xxxxxxxxxxxxx] On Behalf Of Costanzo, Ray
        Sent: 09 November 2006 13:02
        To: windows2000@xxxxxxxxxxxxx
        Subject: [windows2000] Re: Delete Utility

         

        Correction to script.  This would NOT delete zips in a situation
where there's a directory with your special name that contains a
subdirectory that SHOULD have its zips deleted.  Here is the corrected
script:

         

        delzips.vbs:

        Option Explicit

         

        Const ROOT_PATH = "R:\temp" 
        Const NO_DELETE = "nodeldir"  ''name of directory to keep
        Dim oFSO

         

        Call Main()

         

        Sub Main
         Set oFSO = CreateObject("Scripting.FileSystemObject")
         Call Delzips(oFSO.GetFolder(ROOT_PATH))
        End Sub

         

        Sub Delzips(dir)
         Dim oSubdir, oFile
         For Each oSubdir in dir.Subfolders
          Call Delzips(oSubdir)
         Next
         
         If dir.Name <> NO_DELETE Then 
          'oFSO.DeleteFile(oFSO.BuildPath(dir.Path, "*.zip"))
          WScript.Echo "Would delete " & oFSO.BuildPath(dir.Path,
"*.zip")
         End If
        End Sub

         

        Ray at work

                -----Original Message-----
                From: windows2000-bounce@xxxxxxxxxxxxx
[mailto:windows2000-bounce@xxxxxxxxxxxxx] On Behalf Of Ray Costanzo
                Sent: Thursday, November 09, 2006 7:59 AM
                To: windows2000@xxxxxxxxxxxxx
                Subject: [windows2000] Re: Delete Utility

                Here, try this script.  Register cscript as the default
script handler so that the "wscript.echo" lines don't attack you with a
million messageboxes.  Notice that the line that would actually delete
the files is commented out.  If it turns out this would work for you,
just uncomment that line by deleting the apostrophe.

                 

                To register cscript, open a command prompt and enter:

                cscript //h:cscript

                 

                delzips.vbs:

                Option Explicit

                 

                Const ROOT_PATH = "R:\temp" 
                Const NO_DELETE = "nodeldir"  ''name of directory to
keep
                Dim oFSO

                 

                Call Main()

                 

                Sub Main
                 Set oFSO = CreateObject("Scripting.FileSystemObject")
                 Call Delzips(oFSO.GetFolder(ROOT_PATH))
                End Sub

                 

                Sub Delzips(dir)
                 Dim oSubdir, oFile
                 For Each oSubdir in dir.Subfolders
                  If oSubdir.Name <> NO_DELETE Then Call
Delzips(oSubdir)
                 Next
                 
                 If dir.Name <> NO_DELETE Then 
                  'oFSO.DeleteFile(oFSO.BuildPath(dir.Path, "*.zip"))
                  WScript.Echo "Would delete " &
oFSO.BuildPath(dir.Path, "*.zip")
                 End If
                End Sub

                 

                 

                Here's the directory structure I tested it against.  It
worked as expected.

                 

                R:\temp>dir /s /b
                R:\temp\delzips.vbs
                R:\temp\dir1
                R:\temp\dir2
                R:\temp\dir3
                R:\temp\dir4
                R:\temp\zipdelete.cmd
                R:\temp\dir1\file.zip
                R:\temp\dir1\subdir1
                R:\temp\dir1\subdir2
                R:\temp\dir1\subdir3
                R:\temp\dir1\subdir1\fil23.zip
                R:\temp\dir1\subdir1\filaassd.zip
                R:\temp\dir1\subdir1\filasd.zip
                R:\temp\dir1\subdir1\file.zip
                R:\temp\dir1\subdir1\file3.zip
                R:\temp\dir1\subdir1\fsd.zip
                R:\temp\dir1\subdir2\fil23.zip
                R:\temp\dir1\subdir2\filaassd.zip
                R:\temp\dir1\subdir2\filasd.zip
                R:\temp\dir1\subdir2\file.zip
                R:\temp\dir1\subdir2\file3.zip
                R:\temp\dir1\subdir2\fsd.zip
                R:\temp\dir1\subdir3\fil23.zip
                R:\temp\dir1\subdir3\filaassd.zip
                R:\temp\dir1\subdir3\filasd.zip
                R:\temp\dir1\subdir3\file.zip
                R:\temp\dir1\subdir3\file3.zip
                R:\temp\dir1\subdir3\fsd.zip
                R:\temp\dir2\file.zip
                R:\temp\dir2\file2.zip
                R:\temp\dir2\subdir1
                R:\temp\dir2\subdir2
                R:\temp\dir2\subdir3
                R:\temp\dir2\subdir1\fil23.zip
                R:\temp\dir2\subdir1\filaassd.zip
                R:\temp\dir2\subdir1\filasd.zip
                R:\temp\dir2\subdir1\file.zip
                R:\temp\dir2\subdir1\file3.zip
                R:\temp\dir2\subdir1\fsd.zip
                R:\temp\dir2\subdir2\fil23.zip
                R:\temp\dir2\subdir2\filaassd.zip
                R:\temp\dir2\subdir2\filasd.zip
                R:\temp\dir2\subdir2\file.zip
                R:\temp\dir2\subdir2\file3.zip
                R:\temp\dir2\subdir2\fsd.zip
                R:\temp\dir2\subdir2\nodeldir
                R:\temp\dir2\subdir2\subsubdir1
                R:\temp\dir2\subdir2\nodeldir\fil23.zip
                R:\temp\dir2\subdir2\nodeldir\filaassd.zip
                R:\temp\dir2\subdir2\nodeldir\fsd.zip
                R:\temp\dir2\subdir2\subsubdir1\filaassd.zip
                R:\temp\dir2\subdir2\subsubdir1\filasd.zip
                R:\temp\dir2\subdir2\subsubdir1\file.zip
                R:\temp\dir2\subdir2\subsubdir1\file3.zip
                R:\temp\dir2\subdir3\fil23.zip
                R:\temp\dir2\subdir3\filaassd.zip
                R:\temp\dir2\subdir3\filasd.zip
                R:\temp\dir2\subdir3\file.zip
                R:\temp\dir2\subdir3\file3.zip
                R:\temp\dir2\subdir3\fsd.zip
                R:\temp\dir3\fil23.zip
                R:\temp\dir3\filaassd.zip
                R:\temp\dir3\filasd.zip
                R:\temp\dir3\file.zip
                R:\temp\dir3\file3.zip
                R:\temp\dir3\fsd.zip
                R:\temp\dir4\fddile.zip
                R:\temp\dir4\fdile.zip
                R:\temp\dir4\fdirle.zip
                R:\temp\dir4\ffddile.zip
                R:\temp\dir4\file.zip
                R:\temp\dir4\subdir1
                R:\temp\dir4\subdir2
                R:\temp\dir4\subdir3
                R:\temp\dir4\subdir1\fil23.zip
                R:\temp\dir4\subdir1\filaassd.zip
                R:\temp\dir4\subdir1\filasd.zip
                R:\temp\dir4\subdir1\file.zip
                R:\temp\dir4\subdir1\file3.zip
                R:\temp\dir4\subdir1\fsd.zip
                R:\temp\dir4\subdir2\fil23.zip
                R:\temp\dir4\subdir2\filaassd.zip
                R:\temp\dir4\subdir2\filasd.zip
                R:\temp\dir4\subdir2\file.zip
                R:\temp\dir4\subdir2\file3.zip
                R:\temp\dir4\subdir2\fsd.zip
                R:\temp\dir4\subdir3\fil23.zip
                R:\temp\dir4\subdir3\filaassd.zip
                R:\temp\dir4\subdir3\filasd.zip
                R:\temp\dir4\subdir3\file.zip
                R:\temp\dir4\subdir3\file3.zip
                R:\temp\dir4\subdir3\fsd.zip

                 

                Ray at home

                 

                 

                
________________________________


                From: windows2000-bounce@xxxxxxxxxxxxx
[mailto:windows2000-bounce@xxxxxxxxxxxxx] On Behalf Of Steve Rance
                Sent: Thursday, November 09, 2006 7:35 AM
                To: windows2000@xxxxxxxxxxxxx
                Subject: [windows2000] Re: Delete Utility

                Thanks Ray, but we are talking hundreds of identically
named folders that need excluding... I don't fancy moving them then
moving them back.  I just though that as the delete functions built into
Windows are very limited someone must have written a fancy delete
utility.

                 

                
________________________________


                From: windows2000-bounce@xxxxxxxxxxxxx
[mailto:windows2000-bounce@xxxxxxxxxxxxx] On Behalf Of Ray Costanzo
                Sent: 09 November 2006 12:12
                To: windows2000@xxxxxxxxxxxxx
                Subject: [windows2000] Re: Delete Utility

                 

                Hi Steve,

                 

                If this is just a one time thing, what you could do is
just do a search in Windows Explorer for the directory name that
contains files you want to keep.  After they're all displayed, cut and
paste them above the root of the directory from which you want to start
traversing and deleting.  After they're safely moved, do a search for
*.zip and delete all the results.  Then move the directories back.

                 

                Ray at home

                 

                
________________________________


                From: windows2000-bounce@xxxxxxxxxxxxx
[mailto:windows2000-bounce@xxxxxxxxxxxxx] On Behalf Of Steve Rance
                Sent: Thursday, November 09, 2006 6:37 AM
                To: Windows2000@xxxxxxxxxxxxx
                Subject: [windows2000] Delete Utility

                Hi Guys,

                 

                Anyone know of a freeware utility that allows mass
deletion of files based on a criteria that will include exclusions of
directories?

                 

                Basically, I need to delete over 50Gb of Zip files on
one of our file servers with hundreds of deep directories, but exclude
zip files within directories with a particular name (or which there will
be hundreds).

                 

                I have just spent over an hour on google but didn't find
anything that even came close to providing this functionality.

                 

                Thanks for any help.

                 

Other related posts: