Issues:
#1 - Don't comment out "use strict"
#2 - $_[0] is the wrong variable. Should be $_. If you are unsure about default variables, don't use them. Instead assign a name to things to avoid confusion.
#3 - readdir will give you the default dir references '.' and '..'. This is the source of your problem with moving the source directory. You must grep those out.
#4 - chomp'ing a filename serves no purpose.
#5 - Your (@files eq "") serves no purpose. That is a string comparison and will always fail. If you want to test if @files contains anything just do if (@files). But even that statement is pointless as you are not changing the value of @files ever.
General Readme:
http://perldoc.perl.org/File/Copy.html - #!/usr/bin/perl
-
-
use warnings;
-
use strict;
-
-
use File::Copy;
-
-
my $srcdir = "/home/tibco/Susan/drop/";
-
my $dest = "/home/tibco/AIS_FTP/3Com/inbound/Staging/";
-
-
opendir(DIR, $srcdir) or die "Can't open $srcdir: $!";
-
@files = grep {!/^\.+$/} readdir(DIR);
-
close(DIR);
-
-
foreach my $file (@files) {
-
my $old = "$srcdir/$file";
-
-
move($old, $dest) or die "Move $old -> $dest failed: $!";
-
print "File Name: $file moved to FTP - 30 mins for next upload.\n\n";
-
sleep 1800; # 30 Minutes
-
}
The above is a cleaned up version of your code that should work now. I believe that most likely your logic is incomplete though. If you are waiting 30 minutes after each file, what happens if the source directory changes? I believe that you should search that directory before each move, which would make the code the following:
- #!/usr/bin/perl
-
-
use warnings;
-
use strict;
-
-
use File::Copy;
-
-
my $srcdir = "/home/tibco/Susan/drop/";
-
my $dest = "/home/tibco/AIS_FTP/3Com/inbound/Staging/";
-
-
for (;;) {
-
opendir(DIR, $srcdir) or die "Can't open $srcdir: $!";
-
@files = grep {!/^\.+$/} readdir(DIR);
-
close(DIR);
-
-
if (!@files) {
-
print "Script ended all files are in FTP.\n\n";
-
last;
-
}
-
-
my $file = $files[0];
-
my $old = "$srcdir/$file";
-
-
move($old, $dest) or die "Move $old -> $dest failed: $!";
-
print "File Name: $file moved to FTP - 30 mins for next upload.\n\n";
-
sleep 1800; # 30 Minutes
-
}