Delete VBS Files

I need a script of some sort that will find all .vbs files on a server and delete them, would perfer to run remotely. I do need a log file..need ASAP and am willing to pay the points to get it...Thanks

Lamar
lamar1Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

maneshrCommented:
are you looking for those files in any particular directory or the entire server?

what os do you have?? (UN*X or Win* or others)

i have a script for UNIX that does what you want. i will also add the log feature to it, so that it fits your requirement.

0
lamar1Author Commented:
I need it for NT, will it work?
0
maneshrCommented:
with minor modifications, it will.

also let me know about the search location (entire server/only certain dir).


you have posted this question twice. pl delete one of them.
0
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

lamar1Author Commented:
I need it to search the entire server, drives C,E,G,H,I,J  the last 4 drives are 130gb drives.
Server name DMOS2
Thanks
0
pitonyakCommented:


Depending on what kind of speed that you require, you may want to use something faster than perl.

You are probably better off running with what maneshr has but since I already have this around...

If time is not critical, perl is about as fast as they come for development...
A simple script that I use to wipe my bak files follows:


# By Andrew D. Pitonyak
# pitonyak@bigfoot.com

use strict;
use LogFile;
my $my_log  = new LogFile;
$my_log = new LogFile;
$my_log->log_front("DelSpec");
$my_log->screen_echo(1);

sub dumb_del($$)
{
    my ($dir_name, $wild_card) = @_;
    foreach (grep(-f $_, glob("$dir_name$wild_card")))
    {
        $my_log->write_log("W", 10, "$_");
        #
        # You really should do some more here to check the status to
        # see if you can delete it. If not you should set it so that
        # you can.
        #
        unlink($_);
    }
    foreach (grep(-d $_, glob("$dir_name\*")))
    {
        dumb_del("$_\\", $wild_card);
    }
}

sub smart_recursive_del($)
{
    my $dir_name = shift;
    my $wild_card = '*.bak';
    if (not -d $dir_name)
    {
        print "Directory $dir_name does not exist\n";
    }
    else
    {
        $dir_name .= '\\' if $dir_name !~ /\\$/;
        $my_log->write_log("I", 1, "Deleting file spec $wild_card from $dir_name");
        dumb_del($dir_name, $wild_card);
    }
}


foreach (@ARGV) {
    smart_recursive_del($_);
}


I ran the program as

perl -w DelSpec.pl \devsrc

You would need to give the list of all your directories that you wanted scanned such as

perl -w DelSpec.pl c:\ d:\ e:\ f:\

Of course you do not have my log routines which produced a log by the name

DelSpec.20000504.2142.log

Which gives me a time date stamp in the file name as

DelSpec.YYYYMMDD.hhmm.log

If you need it I can send you the libraries but you could also simply open a file
and simply dump the data to it. The output follows.
This includes a time date stamp for each action.

DelSpec-I-0001-20000504.214208 | Deleting file spec *.bak from \devsrc\
DelSpec-W-0010-20000504.214209 | \devsrc\base\genlib\pub\DynamicPtrArray.bak
DelSpec-W-0010-20000504.214210 | \devsrc\except\BaseException.bak
DelSpec-W-0010-20000504.214210 | \devsrc\except\interval\DenseVector.bak
DelSpec-W-0010-20000504.214210 | \devsrc\except\interval\interval.bak
DelSpec-W-0010-20000504.214210 | \devsrc\except\interval\IntervalException.bak
DelSpec-W-0010-20000504.214210 | \devsrc\except\interval\PolyBase.bak
DelSpec-W-0010-20000504.214210 | \devsrc\except\interval\PolyDense.bak
DelSpec-W-0010-20000504.214210 | \devsrc\except\interval\PolyType.bak
DelSpec-W-0010-20000504.214210 | \devsrc\except\interval\ok\interval.bak
DelSpec-W-0010-20000504.214211 | \devsrc\except\newbak\ADPSleep.bak
DelSpec-W-0010-20000504.214211 | \devsrc\except\newbak\ADPStrCmp.bak
DelSpec-W-0010-20000504.214211 | \devsrc\except\newbak\adpstrng.bak
DelSpec-W-0010-20000504.214211 | \devsrc\except\newbak\GenConfig.bak
DelSpec-W-0010-20000504.214213 | \devsrc\java\Test.bak
DelSpec-W-0010-20000504.214214 | \devsrc\java\com\qwest\mbus\javadoc\build_doc.bak
DelSpec-W-0010-20000504.214215 | \devsrc\java\com\qwest\mbus\util\Logger.bak
DelSpec-W-0010-20000504.214215 | \devsrc\java\com\qwest\mbus\util\LoggerFile.bak
DelSpec-W-0010-20000504.214215 | \devsrc\java\com\qwest\mbus\util\LoggerOutputStreamNoOpen.bak
DelSpec-W-0010-20000504.214215 | \devsrc\java\com\qwest\mbus\util\LogManager.bak
DelSpec-W-0010-20000504.214215 | \devsrc\java\com\qwest\mbus\util\MBusSyntaxException.bak
DelSpec-W-0010-20000504.214215 | \devsrc\java\com\qwest\mbus\util\StringUtilityFuncs.bak
DelSpec-W-0010-20000504.214215 | \devsrc\java\com\qwest\mbus\util\XMLSimpleDoc.bak
DelSpec-W-0010-20000504.214215 | \devsrc\java\javadoc\build_doc.bak
DelSpec-W-0010-20000504.214218 | \devsrc\java\lib\qwest\mbus\connector\build_con.bak
DelSpec-W-0010-20000504.214218 | \devsrc\java\lib\qwest\mbus\connector\Connector.bak
DelSpec-W-0010-20000504.214218 | \devsrc\java\lib\qwest\mbus\connector\ConnectorManager.bak
DelSpec-W-0010-20000504.214218 | \devsrc\java\lib\qwest\mbus\connector\Maps.bak
DelSpec-W-0010-20000504.214218 | \devsrc\java\lib\qwest\mbus\connector\PortMonitor.bak
DelSpec-W-0010-20000504.214218 | \devsrc\java\lib\qwest\mbus\util\MBusSyntaxException.bak
DelSpec-W-0010-20000504.214218 | \devsrc\java\lib\qwest\mbus\util\SocketUtil.bak
DelSpec-W-0010-20000504.214218 | \devsrc\java\lib\qwest\mbus\util\XmlCreator.bak
DelSpec-W-0010-20000504.214223 | \devsrc\java\ts\bak\Test.bak
DelSpec-W-0010-20000504.214223 | \devsrc\java\ts\java\ADPThread.bak
DelSpec-W-0010-20000504.214223 | \devsrc\java\util\Logger.bak
DelSpec-W-0010-20000504.214223 | \devsrc\java\util\LoggerFile.bak
DelSpec-W-0010-20000504.214223 | \devsrc\java\util\LoggerOutputStreamNoOpen.bak
DelSpec-W-0010-20000504.214223 | \devsrc\java\util\LogManager.bak
DelSpec-W-0010-20000504.214223 | \devsrc\java\util\MBusSyntaxException.bak
DelSpec-W-0010-20000504.214223 | \devsrc\java\util\StringUtilityFuncs.bak
DelSpec-W-0010-20000504.214223 | \devsrc\java\util\XMLSimpleDoc.bak
DelSpec-W-0010-20000504.214224 | \devsrc\mike\MyList.bak
DelSpec-W-0010-20000504.214224 | \devsrc\mike\shootNode.bak
DelSpec-W-0010-20000504.214224 | \devsrc\perl\car3142.bak
DelSpec-W-0010-20000504.214224 | \devsrc\perl\ftp\t.bak
DelSpec-W-0010-20000504.214226 | \devsrc\perl\learn\args.bak
DelSpec-W-0010-20000504.214226 | \devsrc\perl\learn\foo.bak
DelSpec-W-0010-20000504.214226 | \devsrc\perl\learn\scope.bak
DelSpec-W-0010-20000504.214226 | \devsrc\perl\learn\strict.bak
DelSpec-W-0010-20000504.214226 | \devsrc\perl\mike\foo.bak
DelSpec-W-0010-20000504.214226 | \devsrc\perl\mike\smbpasswd.bak
DelSpec-W-0010-20000504.214226 | \devsrc\perl\mike\test.bak
DelSpec-W-0010-20000504.214227 | \devsrc\perl\mike\tst.bak
DelSpec-W-0010-20000504.214227 | \devsrc\perl\mike\tmp\StrFmt.bak
DelSpec-W-0010-20000504.214227 | \devsrc\perl\mike\tmp\Test.bak
DelSpec-W-0010-20000504.214227 | \devsrc\perl\mike\tmp\TimeDate.bak
DelSpec-W-0010-20000504.214227 | \devsrc\perl\mike\tmp\tst.bak
DelSpec-W-0010-20000504.214227 | \devsrc\perl\pchmod\deps.bak
DelSpec-W-0010-20000504.214227 | \devsrc\perl\pchmod\mike.bak
DelSpec-W-0010-20000504.214227 | \devsrc\perl\pchmod\WalkDir.bak
DelSpec-W-0010-20000504.214227 | \devsrc\perl\test\DelSpec.bak
DelSpec-W-0010-20000504.214227 | \devsrc\perl\test\dump.bak
DelSpec-W-0010-20000504.214227 | \devsrc\perl\test\test.bak
DelSpec-W-0010-20000504.214227 | \devsrc\perl\test\TreeSize.bak
DelSpec-W-0010-20000504.214227 | \devsrc\perl\test\tst.bak
DelSpec-W-0010-20000504.214227 | \devsrc\ts\adpstrng.bak
DelSpec-W-0010-20000504.214228 | \devsrc\ts\linux\ADPSTRNG.bak
DelSpec-W-0010-20000504.214228 | \devsrc\ts\linux\MYCONFIG.bak
DelSpec-W-0010-20000504.214228 | \devsrc\ts\linux\BAK2\ADPSTRNG.bak
DelSpec-W-0010-20000504.214228 | \devsrc\ts\linux\BAK2\MYCONFIG.bak

0
ozoCommented:
use File::Find;
find(sub{/\.vbs$/ && (unlink($_) || warn "$name: $!")},qw(C: E: G: H: I: J:));
0
lamar1Author Commented:
I'll have to check these out and let you know.
ozo I get the following when your script starts.
Name "mani::name" used only once: possible type at find.pl line 2.

Lamar
0
lamar1Author Commented:
maneshr, what happened to you, I was expecting you to post your script    Lamar
0
lamar1Author Commented:
TYPO of my own.

I'll have to check these out and let you know.
ozo I get the following when your script starts.
Name "main::name" used only once: possible type at find.pl line 2.

                        Lamar
0
lamar1Author Commented:
Typo of my own (part 2)

I'll have to check these out and let you know.
 ozo I get the following when your script starts.
Name "mani::name" used only once: possible typo at find.pl line 2.

                        Lamar
0
maneshrCommented:
lamar1,

here is the quick-n-dirty solution that i have.

===============my_del.pl
$|++;

## Add the drives you want to delete from here.
@drives=("c","D");
## specify the type of files you want to delete
$pattern="*.vbs";

foreach $drive (@drives){
  $tmp=$drive.":\\".$pattern;
  $var=`dir $tmp /s`;
  @var=split(/\n/,$var);
  foreach(@var){
    if (/\s+Directory of(.*)/){
      $cur_dir=$1;
    }

    if (/^\d{2}\/\d{2}\/\d{2}\s+\d+:\d+.\s+(.*)/){
      ($size,$file_name)=split(/\s+/,$1,2);
      $file_to_be_deleted=$cur_dir."\\".$file_name."\n";
      `del /p $file_to_be_deleted 2> null`;
      push(@deleted_files,$file_to_be_deleted);
    }
  }
}

## Write the list of files that matched your pattern in the log file.
open(LOG,">>/temp/log") || die $!;
foreach(@deleted_files){
  print LOG $_;
}
close(LOG);
0
lamar1Author Commented:
I'll test it and let you know, thanks for your efforts..Lamar
0
maneshrCommented:
Sure.

have a nice weekend. :-)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TubaCommented:
Follow this link to download a program that will erase the Loveletter virus and the files overwritten by it

http://www.atremo.se/loveletter/clean.vbs

Doubleklick to execute it

0
lamar1Author Commented:
Why would I want a virus cleaner, this is not what I asked for, this is for something entirely different, I have some mis-behaving vbs scripts that I can't pinpoint and need to remove them so I can do a restore from a know good set of backups, before the problem started...Thanks anyway.
0
tgoetzeCommented:
Adding case independence, logging output (to stdout) and removing the compile error from ozo's answers follows:

use File::Find;
find(sub{/\.vbs$/i && (print "$File::Find::name\n") && (unlink($_) || warn "$File::Find::name: $!")},qw(C:\ E:\ H:\ I:\ J:\));

You'll get a line for each file deleted and possibly a line if there was an error deleting it.
0
lamar1Author Commented:
Worked fine, thanks for your help...Lamar
0
maneshrCommented:
lamar1,

Glad to know that your problem was resolved.

Rgds
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.