Loading ...
Sorry, an error occurred while loading the content.

Re: Delete non-empty directories.

Expand Messages
  • daymobrew@yahoo.com
    ... File::Path is a standard module so should be installed. use File::Path; rmtree( $remove ); This will remove the entire directory tree $remove, even if it
    Message 1 of 2 , Jul 27, 2004
    • 0 Attachment
      --- In perl-beginner@yahoogroups.com, "zeshanism" <zeshanism@y...> wrote:
      > How to delete the non-empty directory, which can contain other sub-
      > directories and files.
      >
      > IF it contains the Files only, it's no problem. First delete the
      > files and then the directory.
      >
      > ---------------------------------------
      > $remove = "/home/blah/blah";
      >
      > #Empty Directory, delete all Files within it.
      >
      > unlink glob "$remove/* $remove/.*";
      >
      > #Now delete this empty directory.
      >
      > rmdir $remove;
      > ---------------------------------------
      >
      > I am experiencing problem, what If it contains the sub-directories?
      > I want to delete directory even if contains files or sub-directories.
      >
      > Any simple way to do it?
      >
      > Don't refer me to cpan File::Remove as I have no root access and
      > it's not installed on my Server.
      >
      > Thanks,
      > Zeshan.

      File::Path is a standard module so should be installed.

      use File::Path;
      rmtree( $remove );

      This will remove the entire directory tree $remove, even if it
      contains non-empty directories.

      perldoc File::Path
    Your message has been successfully submitted and would be delivered to recipients shortly.