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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Growing

Status
Not open for further replies.

M626

Programmer
Mar 13, 2002
299
0
0
Does anyone know of a simple, say two lines of code i can use to test if a file is growing, and if it's not move it to a unc path?
 
I would suggest you have a look at the stat() function.

Code:
    ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
       $atime,$mtime,$ctime,$blksize,$blocks)
           = stat($filename);

Not all fields are supported on all filesystem types. Here are the meanings of the fields:

  0 dev      device number of filesystem
  1 ino      inode number
  2 mode     file mode  (type and permissions)
  3 nlink    number of (hard) links to the file
  4 uid      numeric user ID of file's owner
  5 gid      numeric group ID of file's owner
  6 rdev     the device identifier (special files only)
  7 size     total size of file, in bytes
  8 atime    last access time in seconds since the epoch
  9 mtime    last modify time in seconds since the epoch
 10 ctime    inode change time in seconds since the epoch (*)
 11 blksize  preferred block size for file system I/O
 12 blocks   actual number of blocks allocated
 
I have the following script but it never moves the file... does anyone see why it might not be working??

#!/usr/bin/perl
use File::stat;

$req = "D:\\Temp\\In"; #give the location of the source files

opendir(DIR ,"$req") or die "cannot open $req";
$outfile = "list.txt";
open OUT, ">$outfile" or die "Cannot open $outfile";

%hash =0;
while (defined($doc = readdir(DIR)))
{

if($doc eq "\." || $doc eq "\..")
{
#do nothing;
}
else
{
if($doc !~ /\./)
{
}
else{
$file = $doc;
chdir $req;
$st = stat($doc) or die "No $doc: $!";
$original_time = $st -> mtime;
$new_time = $st -> mtime;
$hash{$newtime} = 1;
$flag = 0;
while($flag == 0)
{
$st = stat($file);
$new_time = $st -> mtime;
print "Time: " . $new_time . "\n";
$hash{$newtime} = $hash{$newtime} + 1;
if($hash{$newtime} != 1)
{

`mv "S:\\Temp\\Out"/$doc source2`; # give the full path of the source(append $doc) and the destination
print OUT "$doc\n"; #the list of moved files
$flag = 1;
}
sleep 3;
}
}
}


}

close OUT;
 
Well, for one thing, do you really mean
Code:
if($doc !~ /\./){}
?!?

You might want to use grep to get you the right file names:

Have a look at this
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top