Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading contents of subfolders and deleting based on timestamp

Status
Not open for further replies.

EchoCola

Programmer
Apr 13, 2004
48
US
I just wanted to get some tips as how to get the time stamp, this is on a windows environment but I'm able to execute some unix commands thanks to the MKS kit. Anywho, here is my code tell me what I'm doing wrong! :)
Code:
#This script searches the folders in the current
#directory, if it empty it deletes the directory
#If it contains something, it will leave it alone

$directory_one = 'Y:\archive1\\';
system(cls);

print "\nProcessing 1, Please wait...\n";

chdir($directory_one) ||
  die "Cannot change directory to $directory_one: $!";
		
opendir(directory,".") ||				
  die "Cannot open the directory . (Directory may not exist): $!";

@folder_list = <*>;

system(cls);
print "\nProcessing 2, Please wait...\n";

foreach $application (@folder_list){
	@releases = qx("ls -lR $application");
		
		foreach $release (@releases){
			($READTIME, $WRITETIME) = (stat($release))[8,9];
			print "Release: $realease\n";
			#print "Readtime: $READTIME \n";
			#print "WriteTime: $WRITETIME \n";
		}
		print "\n=================================================================\n";	
}


 



closedir(directory);
 
PS: I would rather not have code!! Just ideas! :)
 
My first suggestion would be to add:

use strict;
use warnings;

at the top of your script

:)
 
Take a look at the perl functions on file information.

Hint: On a Windows machine, get a command prompt and type 'perldoc -f -M'

- Rieekan
 
Hi

You said that you don't want perl code, but anyway you might calculate the timestamp of the file, here an example:

my $file;
my $PATHSOURCE = "/m/ossetc/configurator/rac/planmg/npsxfiles";
my $PATHTARGET = "/m/ossetc/configurator/rac/planmg/npsxfiles/old_npsxfiles";

system("clear");

foreach (`ls $PATHSOURCE/*.dat *.xml *.kom`){
$_ =~ s/\s//g;
$file = $_;
my @time = timeconv(-M $file);
system("mv $file $PATHTARGET")if (-d $PATHTARGET and $time[0]>3);
print "The file: $file was modified at $time[0] days ago. Moving $file to $PATHTARGET\n" if (-d $PATHTARGET and $time[0]>3);
}


sub timeconv {
my $time = shift();
my $days = int ($time);
$time = ($time - $days) * 24;
my $hours = int ($time);
$time = ($time - $hours)* 60;
my $minutes = int ($time);
$time = ($time - $minutes) * 60;
my $seconds = int($time);
return ($days,$hours,$minutes,$seconds);
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top