21 Aralık 2014 Pazar

C# Harddisk Doluluk Oranı Bulma Kodları




















using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;

using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace disk_d.oranı
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        static long bilgi(string driveName)
        {
            foreach (DriveInfo drive in DriveInfo.GetDrives())
            {
                if (drive.IsReady && drive.Name == driveName)
                {
                    return ((drive.TotalSize - drive.TotalFreeSpace) * 100) / drive.TotalSize;
                }
            }

            return -1;
        }
   
        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            long yuzzde = bilgi("C:\\");
            long yuzzde2 = bilgi("D:\\");

            if (yuzzde == -1)
            {
                MessageBox.Show("Bir hata oluştu.");
            }
            else
            {
                label1.Text="C Diskinin Doluluk Oranı %" + yuzzde;
            }
            if (yuzzde == -1)
            {
                MessageBox.Show("Bir hata oluştu.");
            }
            else
            {
                label2.Text="D Diskinin Doluluk Oranı %" + yuzzde2;
            }
         
        }
    }
}

Paylaş:

0 yorum:

Yorum Gönder

Popüler

Son

Kategoriler

Arşiv