Author Topic: delete empty folders  (Read 2240 times)

0 Members and 1 Guest are viewing this topic.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
delete empty folders
« on: May 18, 2010, 02:59:25 PM »
Is there a way using .Net to delete empty folders?  I can't seem to find a method for checking, so it must be something so obvious I just dont see it.  Also, Thumbs.db, being a system file is giving me trouble, any ideas for that?

Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Chuck Gabriel

  • Guest
Re: delete empty folders
« Reply #1 on: May 18, 2010, 03:25:37 PM »
Two static functions:

System.IO.Directory.Delete(string)
System.IO.File.SetAttributes(string, System.IO.FileAttributes)

Glenn R

  • Guest
Re: delete empty folders
« Reply #2 on: May 18, 2010, 03:27:57 PM »
Here's one way:

Code: [Select]
DirectoryInfo di = new DirectoryInfo(@"C:\DeleteMe");

            FileInfo[] fileList = di.GetFiles(@"C:\DeleteMe");

            if (fileList == null)
            {
                // safe to delete
                di.Delete();
            }
            else
            {
                // do something here to examine list of returned files...
            }

that's very quick and off the top of my head David...

Glenn R

  • Guest
Re: delete empty folders
« Reply #3 on: May 18, 2010, 03:36:53 PM »
Two static functions:

System.IO.Directory.Delete(string)
System.IO.File.SetAttributes(string, System.IO.FileAttributes)

Hehe Chuck beat me to it....

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: delete empty folders
« Reply #4 on: May 18, 2010, 05:34:25 PM »
thanks guys!  I knew it would be something simple.  Now to see what I can build.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)