Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Size of a Folder

Size of a Folder

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharpquestion
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Yuvi Panda
    wrote on last edited by
    #1

    Well, I've been trying to get the Size of a Folder with .NET without using Recursion. There dosn't seem to be any property for it and all my searches have given me only ways of getting them using Recursion, which I want to avoid at all costs. Any Advice, Guys ? Simply Yuvi Don't Argue with a Fool : People looking will not know the difference

    R 1 Reply Last reply
    0
    • Y Yuvi Panda

      Well, I've been trying to get the Size of a Folder with .NET without using Recursion. There dosn't seem to be any property for it and all my searches have given me only ways of getting them using Recursion, which I want to avoid at all costs. Any Advice, Guys ? Simply Yuvi Don't Argue with a Fool : People looking will not know the difference

      R Offline
      R Offline
      rob tillaart
      wrote on last edited by
      #2

      The directory/folder structure itself is recursive and as far as I know there is no such information stored in any folder. Technically it could be done but if a file changes one should update this information of all the parent folders and that could make it quite expensive. You could a tree structure containing this size information yourself and have it kept up to date by means of a service. Then you only need to ask that service for the size and you would have the answer immediately. But this is far more complex than the recursive algorithm. A unwanted side effect is that such service would take up CPU time and probably would decrease the performance of your disks. Do you have any requirement that ask for instantanious information? If you just want to avoid recursion you could make an iterative directory walking algorithm but that would imply you should keep track on a stack where you have been. It might be a bit faster but it is harder to code. regards, rob tillaart

      Y 1 Reply Last reply
      0
      • R rob tillaart

        The directory/folder structure itself is recursive and as far as I know there is no such information stored in any folder. Technically it could be done but if a file changes one should update this information of all the parent folders and that could make it quite expensive. You could a tree structure containing this size information yourself and have it kept up to date by means of a service. Then you only need to ask that service for the size and you would have the answer immediately. But this is far more complex than the recursive algorithm. A unwanted side effect is that such service would take up CPU time and probably would decrease the performance of your disks. Do you have any requirement that ask for instantanious information? If you just want to avoid recursion you could make an iterative directory walking algorithm but that would imply you should keep track on a stack where you have been. It might be a bit faster but it is harder to code. regards, rob tillaart

        Y Offline
        Y Offline
        Yuvi Panda
        wrote on last edited by
        #3

        Thanks Rob. But, Yes, My App does require Instantanious Information. It is something like (Treesize), but also adds that it can actually operate on the files and folders. And, Since it uses a Chart and by it's Very Nature, changes the information about directories often, it does need instantinous Information... And, I suppose I'd be doing some benchmarks about the time required to get the size of them by Recursion and iteration, but I think that It'd take a lot of time, especially for rather big Folders like the Program Files folder.... Simply Yuvi Don't Argue with a Fool : People looking will not know the difference

        Y 1 Reply Last reply
        0
        • Y Yuvi Panda

          Thanks Rob. But, Yes, My App does require Instantanious Information. It is something like (Treesize), but also adds that it can actually operate on the files and folders. And, Since it uses a Chart and by it's Very Nature, changes the information about directories often, it does need instantinous Information... And, I suppose I'd be doing some benchmarks about the time required to get the size of them by Recursion and iteration, but I think that It'd take a lot of time, especially for rather big Folders like the Program Files folder.... Simply Yuvi Don't Argue with a Fool : People looking will not know the difference

          Y Offline
          Y Offline
          Yuvi Panda
          wrote on last edited by
          #4

          Well, I did run some tests, and it showed that it needs 1 minute 20 seconds to find the size of my primary partition, which is 13 gb full.... And, if i need to get the size of the Program Files Folder inside it, all the Files and Folders Sizes would be queried again! Sure, I could construct a Tree with the Folders and their Sizes, but i suppose there should be a better way.... Simply Yuvi Don't Argue with a Fool : People looking will not know the difference

          R 1 Reply Last reply
          0
          • Y Yuvi Panda

            Well, I did run some tests, and it showed that it needs 1 minute 20 seconds to find the size of my primary partition, which is 13 gb full.... And, if i need to get the size of the Program Files Folder inside it, all the Files and Folders Sizes would be queried again! Sure, I could construct a Tree with the Folders and their Sizes, but i suppose there should be a better way.... Simply Yuvi Don't Argue with a Fool : People looking will not know the difference

            R Offline
            R Offline
            rob tillaart
            wrote on last edited by
            #5

            Hi Yuvi, Two ideas: 1) Monitor 'hot' folders with an other frequency than 'cold' folders. The folder program files is big but does hardly change where the temp folder may be far more active. 2) Use WMI. You can get all kind of events from the OS. Maybe you can subscribe to file (create append delete) events. Then you know where the changes are. I have no experience with it but check http://www.codeproject.com/csharp/WMIproviderGuide.asp[^] for a good backgrounder. regards, rob

            Y 1 Reply Last reply
            0
            • R rob tillaart

              Hi Yuvi, Two ideas: 1) Monitor 'hot' folders with an other frequency than 'cold' folders. The folder program files is big but does hardly change where the temp folder may be far more active. 2) Use WMI. You can get all kind of events from the OS. Maybe you can subscribe to file (create append delete) events. Then you know where the changes are. I have no experience with it but check http://www.codeproject.com/csharp/WMIproviderGuide.asp[^] for a good backgrounder. regards, rob

              Y Offline
              Y Offline
              Yuvi Panda
              wrote on last edited by
              #6

              Thanks for the Ideas, Rob. Will Sure check WMI out.... Simply Yuvi Don't Argue with a Fool : People looking will not know the difference

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups