Roboticus

Using $File::Find::name rather has undesired effects.
#! /usr/ddsperl/bin/perl -w # Testing # Author: #use strict; use diagnostics; use File::Find; # Variable "Error" contains any error of previous task runs. # 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 deletin +g empty directories) should execute my $Error = "0" ; # 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 $DelEmptyFoldrArchive = "no "; # our $ThisSourceDirectory = q|holds the source file location |; our $ThisSourceDirectory = "/home/ssaha/tmp/source/"; #our $ThisSourceDirectory = "\\hostname\share-dir"; if ($ThisSourceDirectory =~ m/^\\\\/ ) { ($ThisSourceDirectory =~ s/[\\]/\\\\/g ) ; } my $file ; if (($DelEmptyFoldrArchive eq "yes ")&&($ThisMoveTarget)) { if (($ThisSourceDirectory)&&("$Error" == 0)) { find({ wanted => \&wanted, no_chdir => 1 }, $ThisSourceDirectory); sub wanted { return unless -f; $file = $_; print STDERR "$file \n " ; } if ($file) { print STDERR "The $ThisSourceDirectory has files pres +ent \n" ; } elsif (!$file) { finddepth (sub { print " directories are $File::Find::name \n"; rmdir $File::Find::name ; # rmdir $_ ; # rmdir }, $ThisSourceDirectory); } } elsif (($ThisSourceDirectory)&&("$Error" != 0)) { print STDERR "JOB Completed with Errors, Source Agent used was SRCHOST +\n" ; } } else { print STDERR "DelEmptyFoldrArchive is $DelEmptyFoldrArchive, + skipping directory deletion. \n" ; }

When used File::Find::name with rmdir , it deletes the source directory itself ($ThisSourceDirectory=/home/ssaha/tmp/source ) upon condition being satisfied (empty directory) and not the constituent sub directories inside. The only two options i am finding safe is "rmdir $_" and "rmdir". Even though they are working as a code test on separate linux environ --on actual test script(code) is only able to delete on windows clients locally (c:\path etc format. Its not able to delete inputs such "\\hostname\share\" not even in Linux ("\usr\local\tmp") type. I think there a possibility that this is because of rmdir not getting full pathname and i am not getting how it could be achieved safely.

output

[scripts]# perl ./testArchive.pl directories are /home/ssaha/tmp/source/dir1/folder directories are /home/ssaha/tmp/source/dir1 directories are /home/ssaha/tmp/source/dir3/folder directories are /home/ssaha/tmp/source/dir3 directories are /home/ssaha/tmp/source/dir2/folder directories are /home/ssaha/tmp/source/dir2 directories are /home/ssaha/tmp/source [root@hostname scripts]# ls -l /home/ssaha/tmp/source ls: /home/ssaha/tmp/source: No such file or directory [root@nuuuniitsahalab scripts]# ls -l /home/ssaha/tmp/ total 0

In reply to Re^10: Remove Script for a Infrastructure file managenet system running embedded perl by sanju7
in thread Remove Script for a Infrastructure file managenet system running embedded perl by sanju7

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.