Re: finding files
- From: "Pegasus [MVP]" <news@xxxxxxxxxxxxx>
- Date: Sat, 5 Dec 2009 08:53:50 +0100
"capt edgar" <captedgar@xxxxxxxxxxxxxx> wrote in message
news:adefaf30-9282-474b-9a34-bbeae5332992@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi there
I'm a newbie to programming but very much willing to work hard and
try. We have about 100 servers and on each servers we have the g drive
and e drive. early this year there were some temp files dumped all
over the 100 servers under variuos folders and subfolders so i have
been assigned a task to clean this up. Any chance someone can guide me
in getting an automated script where all i need to do is enter the
list of servers and the file extension to search and then script would
scan for the file extension on all 100 servers and each of the drives
associated with it.
so far i have the following script
Rem Script created: 01.10.2009 22:24
Rem Author: captedgar
strDir = "c:\"
Set FSO = CreateObject("Scripting.FileSystemObject")
Set objDir = FSO.GetFolder(strDir)
getInfo(objDir)
Sub getInfo(pCurrentDir)
For Each aItem In pCurrentDir.Files
If LCase(Right(CStr(aItem.Name), 3)) = "tmp" Then
'wscript.Echo aItem.Name 'all c:\*.tmp
listed
End If
Next
For Each aItem In pCurrentDir.SubFolders
getInfo(aItem) 'passing recursively
Next
End Sub
Your code will work very nicely, stepping recursively through all folders on
the specified drive. To make it go through all existing drives you could use
the following code:
Const Fixed = 2
Set oFSO = CreateObject("Scripting.FileSystemObject")
For Each oDrive In oFSO.Drives
If oDrive.DriveType = Fixed _
Then getInfo oFSO.GetFolder(oDrive.DriveLetter & ":\")
Next
Sub getInfo(pCurrentDir)
For Each aItem In pCurrentDir.Files
If LCase(Right(CStr(aItem.Name), 3)) = "tmp" _
Then WScript.Echo aItem.Name 'all c:\*.tmp listed
Next
For Each aItem In pCurrentDir.SubFolders
getInfo(aItem) 'passing recursively
Next
End Sub
If you wish to deal with several file extensions then you have to repeat the
process for each extension.
While it would be fairly straightforward to process a list of x servers with
a script running on your own machine, execution would be very slow and you
would choke your network for many hours. This is because the script must
read hundreds of thousands of file names from each server. It would be much
fast to execute the script locally on each server, e.g. like so:
@echo off
for /F %%a in (c:\Servers.txt) do (
psexec.exe -u edgar -p password \\%%a \\YourPC\c$\script.vbs
)
This batch file will do the following:
- It will enumerate your server names from c:\Servers.txt
- It will start a console session at each server, using the
specified user name and password.
- It will invoke the script that you keep on your own machine.
Note that the script represents a security risk because your
account/password is hard coded and visible to anyone working on your
machine.
You can download psexec.exe from www.sysinternals.com.
.
- Follow-Ups:
- Re: finding files
- From: capt edgar
- Re: finding files
- References:
- finding files
- From: capt edgar
- finding files
- Prev by Date: Re: Need to compress files on client side... Is it possible to use vbs for that?
- Next by Date: Re: Need to compress files on client side... Is it possible to use vbs for that?
- Previous by thread: finding files
- Next by thread: Re: finding files
- Index(es):
Relevant Pages
|