Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to remove Folders whose contents are empty
    primarykey
    data
    text
    <p>This question may seem a bit absurd but here goes..</p> <p>I have a directory structure: It has 8 levels. So, for example this is 1 path:</p> <pre><code>C:\Root\Catalogue\000EC902F17F\2\2013\11\15\13 </code></pre> <p>The '2' is an index for a webcam. I have 4 in total. so..</p> <pre><code>C:\Root\Catalogue\000EC902F17F\1\2013\11\15\13 C:\Root\Catalogue\000EC902F17F\2\2013\11\15\13 C:\Root\Catalogue\000EC902F17F\3\2013\11\15\13 C:\Root\Catalogue\000EC902F17F\4\2013\11\15\13 </code></pre> <p>The '000EC902F17F' is my own uuid for my webcam.</p> <pre><code>The '2013' is the year. The '11' is the month. The '13' is the day. </code></pre> <p>When I capture motion the jpegs are saved in a directory that signifies when that image was captured.</p> <p>I have a timer that goes through each directory and create a video file from the images. The images are then deleted.</p> <p>Now, I want to have another timer that will go through each directory to check for empty directories. If they are empty the folder is deleted.</p> <p>This tidy-up timer will look at directories created that are older than the current day it runs.</p> <p>I presently have this:</p> <pre><code>private List&lt;string&gt; GetFoldersToDelete() { DateTime to_date = DateTime.Now.AddDays(-1); List&lt;string&gt; paths = Directory.EnumerateDirectories(@"C:\MotionWise\Catalogue\" + Shared.ActiveMac, "*", SearchOption.AllDirectories) .Where(path =&gt; { DateTime lastWriteTime = File.GetLastWriteTime(path); return lastWriteTime &lt;= to_date; }) .ToList(); return paths; } </code></pre> <p>called by:</p> <pre><code> List&lt;string&gt; _deleteMe = new List&lt;string&gt;(); List&lt;string&gt; _folders2Delete = GetFoldersToDelete(); foreach (string _folder in _folders2Delete) { List&lt;string&gt; _folderContents = Directory.EnumerateFiles(_folder).ToList(); if (_folderContents.Count == 0) { _folders2Delete.Add(_folder); } } for (int _index = 0; _index &lt; _folders2Delete.Count; _index++) { Directory.Delete(_folders2Delete[_index]; } </code></pre> <p>Is there a better way to achieve what I want?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload