Im writing a perl script to delete data based on wether I find certain data. Let me explain. Inside the following dir "/spare/data/sample/" there are 5 levels of 6 directories from A-F like so
so inside /spare/data/sample is
A B C D E F and inside that is the same and so on.
At the very bottomest level will be some files. So they could be at
/spare/data/sample/A/E/E/F/123ghkty6ssdoklh/
sample1
sample2
sample3
The "123ghkty6ssdoklh" is randomized so its never fixed and there could be any number of these directories. There may be a zip file of the above files sample1 etc inside "/spare/data/sample/A/E/E/F/123ghkty6ssdoklh.zip". So what i want to do is check for the above files and if they exists go back one directory and check for the zip file and if it exists delete the directory "123ghkty6ssdoklh" and its contents.
So i have used finddepth to do this like so;
$dir = /spare/data/sample
finddepth(\&removeData, $dir);
sub removeData {
if( $_ eq "sample1" )
{
my $now = cwd;
my $file_dir = $File::Find::dir;
print "Found a sample1 at [$file_dir]\n";
chdir $file_dir;
$now = cwd;
print "Current directory $now\n";
my $zip = `find ../ -name *.zip`;
if ($zip)
{
print "Found a zipped data at $zip\n";
chdir ("..");
$now = cwd;
print "Removing old data at $file_dir\n";
`rm -rf $file_dir`;
}
else
{
print "We didn't find zipped data\n";
}
}
}
So this removes the directory ok but it seems to get lost as a result of deleting the directory;
Can't cd to (/spare/data/sample/) A: No such file or directory
Can't cd to (/spare/data/sample/) C: No such file or directory
Can't cd to (/spare/data/sample/) C: No such file or directory
Can't cd to /spare/data/sample/A/E/E/F/123ghkty6ssdoklh: No such file or directory
Can anyone spot anything wrong, well thats assuming u have made sense of all of above
so inside /spare/data/sample is
A B C D E F and inside that is the same and so on.
At the very bottomest level will be some files. So they could be at
/spare/data/sample/A/E/E/F/123ghkty6ssdoklh/
sample1
sample2
sample3
The "123ghkty6ssdoklh" is randomized so its never fixed and there could be any number of these directories. There may be a zip file of the above files sample1 etc inside "/spare/data/sample/A/E/E/F/123ghkty6ssdoklh.zip". So what i want to do is check for the above files and if they exists go back one directory and check for the zip file and if it exists delete the directory "123ghkty6ssdoklh" and its contents.
So i have used finddepth to do this like so;
$dir = /spare/data/sample
finddepth(\&removeData, $dir);
sub removeData {
if( $_ eq "sample1" )
{
my $now = cwd;
my $file_dir = $File::Find::dir;
print "Found a sample1 at [$file_dir]\n";
chdir $file_dir;
$now = cwd;
print "Current directory $now\n";
my $zip = `find ../ -name *.zip`;
if ($zip)
{
print "Found a zipped data at $zip\n";
chdir ("..");
$now = cwd;
print "Removing old data at $file_dir\n";
`rm -rf $file_dir`;
}
else
{
print "We didn't find zipped data\n";
}
}
}
So this removes the directory ok but it seems to get lost as a result of deleting the directory;
Can't cd to (/spare/data/sample/) A: No such file or directory
Can't cd to (/spare/data/sample/) C: No such file or directory
Can't cd to (/spare/data/sample/) C: No such file or directory
Can't cd to /spare/data/sample/A/E/E/F/123ghkty6ssdoklh: No such file or directory
Can anyone spot anything wrong, well thats assuming u have made sense of all of above