Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9015341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:43:41+00:00 2026-06-16T03:43:41+00:00

I call the following function to check a specific path and get a list

  • 0

I call the following function to check a specific path and get a list from all the folders located in the given path, for each folder it will check what the folder size is.

This works if i have a file in the folder like this.

Givenfolderpath\Underlying_folder\file.txt

But when there is a subdirectory with a file in it, it will not give me the size of the folder.

Givenfolderpath\Underlying_folder\subdirectory\file.txt

This is my code.

public void ListFolders()
    {
        dataGridView1.Rows.Clear();
        DirectoryInfo di = new DirectoryInfo(Properties.Settings.Default.RevitPath);
        DirectoryInfo[] diArr = di.GetDirectories();

        foreach (DirectoryInfo dri in diArr)
        {
            string strCreateTime = dri.LastWriteTime.ToString();
            string strCreateDate = dri.LastWriteTime.ToString();
            string strCreateSize2 = null;
            string strCreateSizeMb = null;
            int strCreateSize3;

            long strCreateSize1 = GetDirectorySize(Properties.Settings.Default.RevitPath + @"\" + dri);
            string strCreateSize = GetSizeReadable(strCreateSize1);

            strCreateTime = strCreateTime.Remove(strCreateTime.LastIndexOf(" "));
            strCreateDate = strCreateDate.Remove(0,strCreateDate.LastIndexOf(" "));
            strCreateSize2 = strCreateSize.Remove(strCreateSize.LastIndexOf(" "));
            strCreateSizeMb = strCreateSize.Remove(0, strCreateSize.LastIndexOf(" "));
            strCreateSize3 = Convert.ToInt32(strCreateSize2);


            if (strCreateSizeMb == " Mb")
            {
                if (strCreateSize3 >= Properties.Settings.Default.FolderSize)
                {
                    notifyIcon1.ShowBalloonTip(20000, "Attention Required!", dri + " exceed the permissible size " + Properties.Settings.Default.FolderSize + " Mb", System.Windows.Forms.ToolTipIcon.Warning);
                }
            }

            int idx = dataGridView1.Rows.Add();
            DataGridViewRow row = dataGridView1.Rows[idx];
            row.Cells["User"].Value = dri;
            row.Cells["Date"].Value = strCreateTime;
            row.Cells["Time"].Value = strCreateDate;
            row.Cells["Size"].Value = strCreateSize2;
            row.Cells["SizeMB"].Value = strCreateSizeMb;
        }

Where does it go wrong?

It will put the data like this.

data in datagrid

static long GetDirectorySize(string p)
        {
            // 1
            // Get array of all file names.
            string[] a = Directory.GetFiles(p, "*.*");
            // 2
            // Calculate total bytes of all files in a loop.
            long b = 0;
            foreach (string name in a)
            {
                // 3
                // Use FileInfo to get length of each file.
                FileInfo info = new FileInfo(name);
                b += info.Length;
            }
            // 4
            // Return total size
            return b;
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:43:43+00:00Added an answer on June 16, 2026 at 3:43 am

    Try replacing the line

    DirectoryInfo[] diArr = di.GetDirectories();
    

    with

    DirectoryInfo[] diArr = di.GetDirectories("*", SearchOption.AllDirectories);
    

    That should iterate over all directories contained in the given one. See for reference MSDN: DirectoryInfo.GetDirectories Method (String, SearchOption) and MSDN: SearchOption.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following function call from a thread: Thread Move = new Thread(){
I want to call the following function from my managed code: short LS_LoadConfig(LS_ID SensorID,LPVARIANT
I call the following function with a mouseover event but it's not working. My
I call the following function with Call GameTimer(FormatDate(objLiveCommentary(DateFirstStarted), WithTime), FormatDate(objLiveCommentary(DateSecondStarted), WithTime), Soccer) And it
Will GHC perform tail-call optimization on the following function by default? The only weird
I am using following function. Whenever i call it that time it will increase
I have the following function in a PHP script, which returns and API call:
I am trying to do the following: function main(callback) { $.ajax('server-side', function() { this.callback.call(hello);
I use the following call to openCV function to perform K-means algorithm: cvKMeans2(points, count,
I have the following C++ function definition, which I am trying to call through

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.