I downloaded your code so I could study it in more detail. Here are some things I noticed:
At this point, I had:
#! /usr/bin/perl -w use strict; use diagnostics; use File::Find; # Variable "ThisMoveTarget" contains destination archive location # path. If this stores a path (i.e if directories are archived) # then the main body of code (i.e walk down the source location # for deleting empty directories) should execute # my $ThisMoveTarget = q|holds location where archive files # should go |; my $ThisMoveTarget = '/home/ssaha/tmp/archive'; # our $DelEmptyFoldrArchive = q|holds yes or no |; our $DelEmptyFoldrArchive = "yes "; # our $ThisSourceDirectory = q|holds the source file location |; our $ThisSourceDirectory = "/home/ssaha/tmp/source/"; #our $ThisSourceDirectory = "\\\\hostname\\share-test"; my $file ; if ($DelEmptyFoldrArchive eq "yes ") { print STDERR "Debug3: entering check1 \n" ; find({ wanted => \&wanted, no_chdir => 1 }, $ThisSourceDirectory); if ($file) { print STDERR "Debug3: entering check2 file is file \n" ; print STDERR "The $ThisSourceDirectory has files present \n" ; } elsif (!$file) { print STDERR "Debug3 entering check3 file is no file\n" ; finddepth (sub { print "rmdir $_\n"; }, $ThisSourceDirectory); } } else { print STDERR "Debug3: entering check5 \n" ; print STDERR "DelEmptyFoldrArchive is $DelEmptyFoldrArchive, skippi +ng directory deletion. \n" ; } sub wanted { return unless -f; $file = $_; print STDERR "$file \n " ; }
At this point, the code is pretty clear, and one of the errors is apparent: Some of the code you probably intended to be in the wanted subroutine was actually following it, so it only checked the last file found at that part. The my $file; declaration was at the outermost scope, and hid that from you. By moving the declaration inside of sub wanted (along with the associated code), it cleans things up a bit more.
I stopped at this point for now, so you can work a little more on it.
Another note: perl works well with forward slashes in paths, even under Windows. You may find it helpful (as I do) to always use forward slashes in paths. It helps portability and you can avoid the headache of quoting backslashes.
...roboticus
In reply to Re^7: Remove Script for a Infrastructure file managenet system running embedded perl
by roboticus
in thread Remove Script for a Infrastructure file managenet system running embedded perl
by sanju7
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |