Β© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#β€’4y agoβ€’
25 replies
Surihia

Is there a way to determine the free space on a drive by using a text file ?

I have a path to a folder which is stored in a text file:
D:\Projects\Videos\current\

I want the program to take the drive letter from the text file and then show the space on the console.

Currently my code is as follows which only shows the free space on my root drive C.
static void Main(string[] args)
        {
            var list = new List<string>();
            var DrivepathTxtFile = new FileStream("LocatedPath.txt", FileMode.Open, FileAccess.Read);


            StreamReader reader = new StreamReader(DrivepathTxtFile);

            string DrivePath;
            while ((DrivePath = reader.ReadLine()) != null)
            {
                list.Add(DrivePath);
            }

            DriveInfo[] Drives = DriveInfo.GetDrives();

            foreach (DriveInfo d in Drives)
            {
                Console.WriteLine(d.TotalFreeSpace);                
                Console.ReadLine();
            }
static void Main(string[] args)
        {
            var list = new List<string>();
            var DrivepathTxtFile = new FileStream("LocatedPath.txt", FileMode.Open, FileAccess.Read);


            StreamReader reader = new StreamReader(DrivepathTxtFile);

            string DrivePath;
            while ((DrivePath = reader.ReadLine()) != null)
            {
                list.Add(DrivePath);
            }

            DriveInfo[] Drives = DriveInfo.GetDrives();

            foreach (DriveInfo d in Drives)
            {
                Console.WriteLine(d.TotalFreeSpace);                
                Console.ReadLine();
            }

I copied the code straight from the MS page and this obviously does not work as the code is picking my C Drive's space.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Is there a way to get Textchunk Width?
C#CC# / help
3y ago
Is there a way to determine if a Winforms .exe is run by double clicking on it on Windows explorer?
C#CC# / help
3y ago
is there any way to make a placeholder text in WPF inside a textbox?
C#CC# / help
3y ago
❔ Is there a way to override the DefaultInterpolatedStringHandler?
C#CC# / help
3y ago