Delete Empty Directory

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ajay m
    New Member
    • Mar 2007
    • 20

    Delete Empty Directory

    hi, i am new to perl
    I am looking for a simple script to delete non empty folder.
    Remove Directory and File(s)
    plz help me...
    Last edited by ajay m; Apr 9 '07, 05:38 AM. Reason: Delete Non Empty Directory
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    perldoc File::Path module

    Comment

    • savanm
      New Member
      • Oct 2006
      • 85

      #3
      Hi,

      Use the following Code

      use File::Find;
      finddepth(sub{r mdir},'.')

      That's it

      Comment

      • savanm
        New Member
        • Oct 2006
        • 85

        #4
        Hi,
        Sorry the above code will delete the Empty Folders

        Comment

        • ajay m
          New Member
          • Mar 2007
          • 20

          #5
          Thank you sir

          Comment

          • antofthy
            New Member
            • Feb 2016
            • 1

            #6
            KevinADC....

            File::Path removes everything. Not just non-empty directories.

            savanm...

            While it is the inverted answer, you are running rmdir on EVERY filename, not just directories or even empty directories. Though That is quite valid as it does the required tests.

            Now to try and answer for real...

            To try and remove directories that are NOT empty, is tricky. A directory with a directory is technically not-empty. So by that criteria, you want to remove any directory that is more than 2 levels deep! That does not sound right.

            So what exactly do you want?

            Delete directories that contain files? Or just...
            Delete all files and leave just the directory structure?

            Basically what do you define as being not-empty?

            Comment

            Working...