0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【C#】ドライブの使用量を算出するプログラムを作ってみた

Last updated at Posted at 2022-07-18

この記事は移転します

どんなときに使うか

ディスクの使用量を調べるときに使うプログラム

動作環境

  • Windows10 21H2
  • dotNETCore 5.0

サンプルコード


using System;
using System.Windows.Forms;
using System.IO;


public class ProcessShow
{
  public static void Main(string[] args){
    
    // 保存先を変えたいときはここを変える
    string file_path = Path.Combine(@""+Environment.MachineName+"_driveInfo"+".txt");
    DriveInfo drive = new DriveInfo("C");
    
    long bitdivide = 1024 * 1024 * 1024;
  
    long CallSpace = drive.AvailableFreeSpace/bitdivide;
    long ALLSpace = drive.TotalSize/bitdivide;
    long TotalFreeSpace = drive.TotalFreeSpace/bitdivide;
    long UseByte = (drive.TotalSize - drive.TotalFreeSpace)/bitdivide;
    
      using (StreamWriter sw = File.AppendText(file_path))
      {
        if (drive.IsReady)
        {
          //DateTime.Now
          sw.WriteLine("呼び出し側が利用できるバイト数"+","+"ドライブ全体のバイト数"+","+"ドライブ全体の空きバイト数"+","+"ドライブ全体の使用容量");
          sw.WriteLine("{0}GB"+","+"{1}GB"+","+"{2}GB"+","+"{3}GB",CallSpace,ALLSpace,TotalFreeSpace,UseByte);
          
        }     
      }
  }
}

おわり

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?