Empty directory: Difference between revisions

Added C# example
(→‎{{header|J}}: reference correct Foreign)
(Added C# example)
Line 49:
/etc/passwd: Not a directory
</pre>
 
=={{header|C#}}==
<lang c#>using System;
using System.IO;
 
class Program
{
static void Main( string[] args )
{
foreach ( string dir in args )
{
Console.WriteLine( "'{0}' {1} empty", dir, IsDirectoryEmpty( dir ) ? "is" : "is not" );
}
}
 
private static bool IsDirectoryEmpty( string dir )
{
return ( Directory.GetFiles( dir ).Length == 0 &&
Directory.GetDirectories( dir ).Length == 0 );
}
}
</lang>
Running it:<pre>
Assume c:\temp exists and is not empty, c:\temp\empty exists and is empty
 
c:\>IsEmptyDir c:\temp c:\temp\empty
'c:\temp' is not empty
'c:\temp\empty' is empty
</pre>
 
 
=={{header|CoffeeScript}}==