codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Crawling the filesystem recursivly and delete files  tauist at 19:24 on Tuesday, August 10, 2010
 

Guys I am learning perl right now and I have been attempting to write a script that starts in the current working directory and find files. Below is the code ..... where did I go wrong?


Any help would be great
_______________________________________________________________________________________________
#!/usr/bin/perl -s

#use warnings;
#use strict;
my $mydir = "/index.html";
my @file = ("foo.bar", "bar.foo", "oof.rab", "rab.oof", "rab.foo", "oof.bar", "foo.bared" );

use Cwd;

sub ScanDirectory{
## The directory we are on now
my ($workdir) = shift;
## Directory place holder
my ($startdir) = $mydir;
## Go to the starting directory
chdir($workdir) or die "Unable to enter dir $workdir:$!\n";
## Open the directory to read contense
opendir(DIR, ".") or die "Unable to open $workdir:$!\n";
## Put everything you find into the array @names
my @names = readdir(DIR) or die "Unable to read $workdir:$!\n";
## close the directory
closedir(DIR);

## Go through the file names found
foreach my $name (@names){

## Do not look at "." or ".."
next if ($name eq ".");
next if ($name eq "..");

## If it is a directory ignore it
if (-d $name){
&ScanDirectory($name);
next;
}

## If the file name is the same as one we are looking for and the "-r" switch is given at the command line Delete the file.
if ($name eq "$file1") {
if (defined $r){
unlink($name) or die "Unable to delete $name:$!\n";
print "found one in $workdir!\n";
}
}
}
## Open the next directory
chdir($startdir) or
die "Unable to change to dir $startdir:$!\n";
}

&ScanDirectory ($cwd);









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Sign up to stay abreast on Open source
•  Re: Write text strings to Serial Port
•  Re: Save up to 80% on SSL Certificates, RapidSSL Certificate @ $ 11.00/yr.
•  Re: IsDate() in JavaScript?
•  Re: horizontal scroll bar for drop down list box
•  Sign Up Now!!To Learn Solr Search Development from the Experts
•  Crawling the filesystem recursivly and delete files
•  Join Now for a free technical webinar on Mastering the Lucene Index
•  HTML 5.0 new Supporting Features


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2010