zoukankan      html  css  js  c++  java
  • 查看硬盘空间

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Management;

    using yy_checkerLib;
    //using ServerDll
    using SICTS_Server;
    namespace jsTest
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            private static string GetSizeUseUnit(string size)
            {
                double dSpace = Convert.ToDouble(size);
                string sSpace = dSpace.ToString("N");
                string[] tmp;
                string rtnSize = "0";
                tmp = sSpace.Split(',');
                switch (tmp.GetUpperBound(0))
                {
                    case 0:
                        rtnSize = tmp[0] + " 字节";
                        break;
                    case 1:
                        rtnSize = tmp[0] + "." + tmp[1].Substring(0, 2) + " K";
                        break;
                    case 2:
                        rtnSize = tmp[0] + "." + tmp[1].Substring(0, 2) + " M";
                        break;
                    case 3:
                        rtnSize = tmp[0] + "." + tmp[1].Substring(0, 2) + " G";
                        break;
                    case 4:
                        rtnSize = tmp[0] + "." + tmp[1].Substring(0, 2) + " T";
                        break;
                }
                return rtnSize;
            }

            private void GetInfo()
            {
                try
                {
                    ManagementClass diskClass = new ManagementClass("Win32_LogicalDisk");
                    ManagementObjectCollection drives = diskClass.GetInstances();
                    string imageSavePath = @"E:\SICTS\image_SIC\";
                    foreach (ManagementObject drv in drives)
                    {
                        if (imageSavePath.StartsWith(drv["Name"].ToString()))
                        {
                            tsbText.Text = "存图空间报告--------截止" +
                                DateTime.Now.ToString("MM月dd日HH时mm分,") +
                                drv["Name"].ToString() + "尚有 " +
                                GetSizeUseUnit(drv["FreeSpace"].ToString()) + " 空间未使用!";
                            this.tsbText.TextAlign = ContentAlignment.MiddleRight;
                            this.tsbText.ImageAlign = ContentAlignment.BottomRight;
                            this.tsbText.TextImageRelation = TextImageRelation.TextBeforeImage;
                            this.tsbText.Spring = true;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                   // Log.WriteToFile(4, "获取失败", "获取存图空间错误,详细情况:" + ex.Message);
                }
            }
            //公司的方法
            public long GetDiskSpace(string strpath)
            {
                long lfreeBytesAvailable = 0;
                long lTotalNumberOfBytes = 0;
                long lTotalNumberOfFreeBytes = 0;
                long lfreeMByteAvailable = 0;
                int index = strpath.IndexOf(@"\");

                try
                {
                    if (index > 0)
                    {
                        string strImageRootpath = strpath.Substring(0, index);
                        ServerDll.GetDiskFreeSpaceEx(strImageRootpath, out lfreeBytesAvailable, out lTotalNumberOfBytes, out lTotalNumberOfFreeBytes);
                        lfreeMByteAvailable = 0;
                        lfreeMByteAvailable = lfreeBytesAvailable / 1024 / 1024 / 1024;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    //Log.WriteToFile("获取磁盘可用空间出错——>", ex.Message);
                }
                return lfreeMByteAvailable;
            }

            private void Form1_Load(object sender, EventArgs e)
            {
               // GetInfo();
                long  nn=GetDiskSpace(@"E:\SICTS\image_SIC\");
                MessageBox.Show(nn.ToString());
            }
        }
    }

  • 相关阅读:
    【拆点费用流】【HDU1853】【 Cyclic Tour】
    【最小费用最大流】【HDU1533】【Going Home】
    【最大流,二分图匹配】【hdu2063】【过山车】
    【最小费用最大流模板】【Uva10806+Spring Team PK】Dijkstra, Dijkstra,
    【最大流之sap】【HDU1532】模板题
    HDU 6130 Kolakoski 思维个屁 水题
    Codeforces 837 D Round Subset DP 思维
    Educational Codeforces Round 26
    Codeforces Round 427 B The name on the board 水题
    Codeforces Round 428 B Game of the rows 贪心 思维
  • 原文地址:https://www.cnblogs.com/xianqingzh/p/1774504.html
Copyright © 2011-2022 走看看