Re: Scripts that delete files, not folders.

Tech-Archive recommends: Fix windows errors by optimizing your registry



Thank you very much. One fix and one problem for me with the deleting empty
folders.

In the first line, I got an error message "Cannot use parentheses when
calling a sub" in which I fixed from a MS article. I had to add Call to the
first line.

After adding that I'm getting error is that I'm getting an error "Object
required: 'fso' in which I'm having a hard time finding the cure.

Here is the code from the post:

DeleteEmptyFolders ("c:\temp", False)

sub DeleteEmptyFolders(sPath, bDeleteThisFolder)

set folder = fso.getfolder(sPath)

'recurse first...
'
for each fldr in folder.subfolders
DeleteEmptyFolders fldr.path,true
next

'if no files or folders then delete...
'
'bDeleteThisFolder is false for
'the root of the subtree, and true for
'sub-folders (unless you want to delete
'the entire subtree if it is empty).
'
if (folder.files.count = 0) and _
(folder.subfolders.count) = 0 and _
bDeleteThisFolder then
on error resume next
folder.delete
exit sub
end if

end sub


"Torgeir Bakken (MVP)" wrote:

> DallasITguy wrote:
>
> > There are/have been post about scripts that delete files by how old they are.
> > Some really good scripts for people like me that are not deep into
> > scripting. Everything that I find is all about deleting files. Is there a
> > way to make the script remove the folder by date or after parsing the files
> > if it's empty? He is a script that I have gotten from the different posts,
> > is there an addition like this to be made?
> >
> > Thanks..
> >
> > (snip coe)
> Hi,
>
> After the file deleting is done, you could make a callout to
> the DeleteEmptyFolders sub found in this post:
>
> http://groups.google.co.uk/group/microsoft.public.scripting.vbscript/msg/0ea7fbd337495cc0?dmode=source&hl=en
>
>
> --
> torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
> Administration scripting examples and an ONLINE version of
> the 1328 page Scripting Guide:
> http://www.microsoft.com/technet/scriptcenter/default.mspx
>
.



Relevant Pages

  • Re: Newbie Question
    ... administrative tasks is "Microsoft Windows 2000 Scripting Guide". ... Using the FileSystemObject to retrieve information on files and folders is ... figure out the paths to the sub directories. ... Dim intIndex ...
    (microsoft.public.scripting.vbscript)
  • Re: Creating Multiple FTP Users and Containers (2000 Server + IIS)
    ... > IIS Administrator for an FTP site. ... > complete Windows Scripting novice so I'm hoping that I can get some help ... > What I am even more unsure of is scripting the creation of Virtual Folders ... The permissions will need to be set to ...
    (microsoft.public.windows.server.scripting)
  • Re: Script for Folder View Customization - Beta
    ... > Are you still using explorer to view folders? ... *removing* view information from a set of folders and then tweaking the ... the shell's scripting modules are just used ... I also use some of the shell ...
    (microsoft.public.scripting.vbscript)
  • Re: Scripts that delete files, not folders.
    ... example I want to delete all files in all folders and subdirectories in the ... >> Call DeleteEmptyFolders (strFolder, False) ... >> DeleteEmptyFolders strFolder, False ... >> torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway ...
    (microsoft.public.windows.server.scripting)
  • Re: Links In Folders
    ... Again, this patch addresses the cross-domain problem, and ... >> folders such as My Documents? ... >> not linked to Control Panel or whatever link I click on. ... >Microsoft MVP Scripting and WMI, ...
    (microsoft.public.win2000.general)