Advertisement
Fhernd

InformacionUnidad.cs

Jul 18th, 2015
875
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | None | 0 0
  1. // OrtizOL - xCSw - http://ortizol.blogspot.com
  2.  
  3. using System;
  4. using System.IO;
  5.  
  6. namespace Receta.CSharp.R0516
  7. {
  8.     public class InformacionUnidad
  9.     {
  10.         public static void Main(string[] args)
  11.         {
  12.             Console.WriteLine(Environment.NewLine);
  13.            
  14.             // Valida la entrada del usuario:
  15.             if (args.Length == 1)
  16.             {
  17.                 DriveInfo unidad = new DriveInfo(args[0]);
  18.                
  19.                 Console.WriteLine ("Espacio disponible en la unidad {0}: {1} KB",
  20.                                    args[0], unidad.AvailableFreeSpace / 1024);
  21.                
  22.                 Console.ReadLine();
  23.                 return;
  24.             }
  25.            
  26.             foreach(DriveInfo unidad in DriveInfo.GetDrives())
  27.             {
  28.                 try
  29.                 {
  30.                     Console.WriteLine ("Espacio disponible en la unidad {0}: {1} KB",
  31.                                        unidad.RootDirectory, unidad.AvailableFreeSpace / 1024);
  32.                 }
  33.                 catch (IOException) // Es posible que unidad de red no esté disponible
  34.                 {
  35.                     Console.WriteLine("[Advertencia]: La unidad {0} no está disponible.", unidad);
  36.                 }
  37.             }
  38.            
  39.             Console.WriteLine(Environment.NewLine);
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement