I'm new to VBS. I'd appreciate if you give me some pointers to achieve
the following:
Search a folder recursively to delete all the files and folders NOT
named *.adb.
Thanks,
Kerr
Ray at home
"w123" <kerr...@abbott.com> wrote in message
news:1121114734.5...@f14g2000cwb.googlegroups.com...
1. search a folder and recursively find all the files and folders that
is NOT *.abs
2. delete all those files and folders
The end result will be cleaned up folder with only the *.abs files
left.
I need help with 1.
Thanks,
w123
2. Michael Harris \(MVP\) Mar 6 2004, 4:08 pm show options
Newsgroups: microsoft.public.scripting.wsh
From: "Michael Harris \(MVP\)" <mikhar at mvps dot org> - Find messages by
this author
Date: Sat, 6 Mar 2004 13:06:46 -0800
Local: Sat,Mar 6 2004 4:06 pm
Subject: Re: Renaming Files
Reply to Author | Forward | Print | Individual Message | Show original |
Report Abuse
> I have hundreds of files that have an underscore in the file name. I
> need to rename the files removing the underscore and replacing it
> with a space. Like this "file_file_file.txt" to "file file file.txt"
> Can I do this with a batch fileor windows script? If not can someone
> suggest a way this can be done.
'===========================================================
' DemoRecursiveFileSearch.vbs
'
' Demonstrates recursive file system search. This
' example searches the folder tree defined by the
' RootPath variable.
'
' In this example, RootPath = "C:\Program Files"
'
' SearchFolders takes a folder object argument and
' walks the Files collection of the folder, passing
' each file object to a SelectFile routine and then
' walks the SubFolders collection of the folder,
' calling itself recursively for each subfolder.
'
' The SelectFile routine applies whatever selection
' criteria is appropriate and adds the file object
' to a global SelectedFiles collection (dictionary).
'
' In this example, files with an extension other than "abs"
' are selected.
'
' On return to the mainline script, the SelectedFiles
' collection is walked and each selected file is
' passed to the ProcessFile routine.
'
' In this example, the full path of each file is
' simply echoed to the console window.
'
'===========================================================
' To adapt this example...
'
' * change the RootPath variable value
' * change the SelectFile selection logic
' * change the ProcessFile processing logic
'
'===========================================================
'
'================================== begin mainline
'
Option Explicit
Dim RootPath
RootPath = "C:\Your Path\To Search"
Dim SelectedFiles
Set SelectedFiles = CreateObject("Scripting.Dictionary")
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Dim RootFolder
Set RootFolder = fso.GetFolder(RootPath)
Call SearchFolders(RootFolder)
WScript.Echo SelectedFiles.Count & " files selected..."
Dim SelectedFile
For Each SelectedFile In SelectedFiles.Items
Call ProcessFile(SelectedFile)
Next
WScript.Echo "Done..."
WScript.Quit
'
'================================== End mainline
'================================== Begin procedures
'
'================================== ProcessFile
'
Sub ProcessFile(argFile)
' echos the file path...
'
' add logic to apply whatever process needed.
'
' e.g., argFile.Delete
'
WScript.Echo argFile.Path
End Sub
'================================== SelectFile
'
Sub SelectFile(argFile)
' echos the file path...
'
' add file to SelectedFiles based on your criteria,
' in this case any file without an "abs" extension...
If LCase(fso.GetExtensionName(argFile.Name, <> "abs") Then
Set SelectedFiles(argFile.Path) = argFile
End If
End Sub
'================================== SearchFolders
'
Sub SearchFolders(argFolder)
Dim file, subfolder
For Each file In argFolder.Files
Call SelectFile(file)
Next
For Each subfolder In argFolder.SubFolders
Call SearchFolders(subfolder)
Next
End Sub
'
'================================== End procedures
--
Michael Harris
Microsoft MVP Scripting
> '================================== SelectFile
> '
> Sub SelectFile(argFile)
>
> ' echos the file path...
> '
> ' add file to SelectedFiles based on your criteria,
> ' in this case any file without an "abs" extension...
>
> If LCase(fso.GetExtensionName(argFile.Name, <> "abs") Then
> Set SelectedFiles(argFile.Path) = argFile
> End If
>
> End Sub
I guess
If LCase(fso.GetExtensionName(argFile.Name)) <> "abs" Then
will work better. :)
--
Gruß, | Bitte in der NG antworten | Win98-Tipps:
Regards, Andreas | Please reply to the NG | http://a-kaestner.de
==================*===========================*=======================72
OE-QuoteFix 1.19.2: http://home.in.tum.de/~jain/software/oe-quotefix/
;-)...
Real code always works better than on the fly air code...