Autor Beitrag
Tobias L
Hält's aus hier
Beiträge: 6

Win XP

BeitragVerfasst: Fr 28.09.07 08:23 
Hi!
Ich versuche momentan in meinem Programm eine Funktion einzufügen, in der der freie Speicher einer bestimmten Laufwerkes ausgelesen und angezeigt werden kann. Welches Laufwerk wird durch den Speicherort einer bestimmten Datei bestimmt.
Ich habe mich schon informiert und ich denke ich muss dazu die Klasse DriveInfo benutzen.

Vielleicht kann mir da jemand helfen und hat eine Idee?

MFG


Moderiert von user profile iconChristian S.: Topic aus C# - Die Sprache verschoben am Sa 29.09.2007 um 16:15
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6386
Erhaltene Danke: 146

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Fr 28.09.07 08:35 
Schonmal in der Hilfe nachgesehen?:
ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
using System;
using System.IO;

class Test
{
    public static void Main()
    {
        DriveInfo[] allDrives = DriveInfo.GetDrives();

        foreach (DriveInfo d in allDrives)
        {
            Console.WriteLine("Drive {0}", d.Name);
            Console.WriteLine("  File type: {0}", d.DriveType);
            if (d.IsReady == true)
            {
                Console.WriteLine("  Volume label: {0}", d.VolumeLabel);
                Console.WriteLine("  File system: {0}", d.DriveFormat);
                Console.WriteLine(
                    "  Available space to current user:{0, 15} bytes"
                    d.AvailableFreeSpace);

                Console.WriteLine(
                    "  Total available space:          {0, 15} bytes",
                    d.TotalFreeSpace);

                Console.WriteLine(
                    "  Total size of drive:            {0, 15} bytes ",
                    d.TotalSize);
            }
        }
    }
}
/* 
This code produces output similar to the following:

Drive A:\
  File type: Removable
Drive C:\
  File type: Fixed
  Volume label: 
  File system: FAT32
  Available space to current user:     4770430976 bytes
  Total available space:               4770430976 bytes
  Total size of drive:                10731683840 bytes 
Drive D:\
  File type: Fixed
  Volume label: 
  File system: NTFS
  Available space to current user:    15114977280 bytes
  Total available space:              15114977280 bytes
  Total size of drive:                25958948864 bytes 
Drive E:\
  File type: CDRom

The actual output of this code will vary based on machine and the permissions
granted to the user executing it.
*/
Tobias L Threadstarter
Hält's aus hier
Beiträge: 6

Win XP

BeitragVerfasst: Fr 28.09.07 09:16 
Ja hab ich schon gelesen. Aber da werden alle Laufwerke angezeigt. Ich brauch das aber nur von einem bestimmten. Ich geb ein Beispiel:

Eine Datenbank liegt auf dem Laufwerk D: also brauch ich nur den freien Speicher D:.
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6386
Erhaltene Danke: 146

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Fr 28.09.07 10:02 
Naj, dann machst Du statt der foreach-Schleife einfach ein:
ausblenden C#-Quelltext
1:
d = new DriveInfo("D");					

Und passt den Rest entsprechend an?
Tobias L Threadstarter
Hält's aus hier
Beiträge: 6

Win XP

BeitragVerfasst: Fr 28.09.07 10:15 
Ja jetz funktionierts.

Danke.