Solved

Delete VBS Files

Posted on 2000-05-04
18
347 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:lamar1
18 Comments
 
LVL 16

Expert Comment

by:maneshr
ID: 2778421
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
 

Author Comment

by:lamar1
ID: 2778427
I need it for NT, will it work?
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2778437
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
 

Author Comment

by:lamar1
ID: 2778451
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
 
LVL 5

Expert Comment

by:pitonyak
ID: 2779264


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
 
LVL 84

Expert Comment

by:ozo
ID: 2779325
use File::Find;
find(sub{/\.vbs$/ && (unlink($_) || warn "$name: $!")},qw(C: E: G: H: I: J:));
0
 

Author Comment

by:lamar1
ID: 2780155
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
 

Author Comment

by:lamar1
ID: 2780157
maneshr, what happened to you, I was expecting you to post your script    Lamar
0
 

Author Comment

by:lamar1
ID: 2780162
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:lamar1
ID: 2780164
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
 
LVL 16

Expert Comment

by:maneshr
ID: 2781497
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
 

Author Comment

by:lamar1
ID: 2781769
I'll test it and let you know, thanks for your efforts..Lamar
0
 
LVL 16

Accepted Solution

by:
maneshr earned 300 total points
ID: 2782412
Sure.

have a nice weekend. :-)
0
 

Expert Comment

by:Tuba
ID: 2783550
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
 

Author Comment

by:lamar1
ID: 2783782
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
 
LVL 3

Expert Comment

by:tgoetze
ID: 2787187
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
 

Author Comment

by:lamar1
ID: 2792104
Worked fine, thanks for your help...Lamar
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2792442
lamar1,

Glad to know that your problem was resolved.

Rgds
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now