473,406 Members | 2,390 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Get Byte Count For Folder And Subfolders

I am working on a windows forms app where I need to do copies. I also
need to show a progress bar. In order to be able to set the Maximum
property for the progress bar and then update it during the copy, I
must determine the total byte count for the folder and subfolders that
the user has selected before the copy begins. I already have this
working in one way, but it is SLOW. Currently, I am crawling (no pun
intended) over each file, checking its size, and then incrementing a
variable to get to the total bytecount in the end. I KNOW there has to
be a faster way. How do I get this information, like from an index or
something? For sure, that would be a much faster way to do it than what
I am doing now. Thanks in advance for any help.

JP

Apr 6 '06 #1
6 3000
I already have this
working in one way, but it is SLOW. Currently, I am crawling (no pun
intended) over each file, checking its size, and then incrementing a
variable to get to the total bytecount in the end. I KNOW there has to
be a faster way.


I don't think there is.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Apr 6 '06 #2
<jo*********@topscene.com> wrote:
I am working on a windows forms app where I need to do copies. I also
need to show a progress bar. In order to be able to set the Maximum
property for the progress bar and then update it during the copy, I
must determine the total byte count for the folder and subfolders that
the user has selected before the copy begins. I already have this
working in one way, but it is SLOW. Currently, I am crawling (no pun
intended) over each file, checking its size, and then incrementing a
variable to get to the total bytecount in the end. I KNOW there has to
be a faster way. How do I get this information, like from an index or
something? For sure, that would be a much faster way to do it than what
I am doing now. Thanks in advance for any help.


Is it much slower than, say, Explorer doing the same thing? (Note that
you probably need to flush any disk caches, eg by rebooting, between
test runs.)

Can you post the code as a short but complete program so we could see
if anything's obviously missing?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 6 '06 #3

<jo*********@topscene.com> wrote in message
news:11********************@i39g2000cwa.googlegrou ps.com...
|I am working on a windows forms app where I need to do copies. I also
| need to show a progress bar. In order to be able to set the Maximum
| property for the progress bar and then update it during the copy, I
| must determine the total byte count for the folder and subfolders that
| the user has selected before the copy begins. I already have this
| working in one way, but it is SLOW. Currently, I am crawling (no pun
| intended) over each file, checking its size, and then incrementing a
| variable to get to the total bytecount in the end. I KNOW there has to
| be a faster way. How do I get this information, like from an index or
| something? For sure, that would be a much faster way to do it than what
| I am doing now. Thanks in advance for any help.
|
| JP
|

How are you checking it's size?
And how are you copying the files?
Willy.
Apr 6 '06 #4
On the first pass, to get the size I am using instances of the FileInfo
class. On the second pass, to copy I am using System.IO File.Copy.

Any suggestions for improvement?

Apr 10 '06 #5

jo*********@topscene.com schreef:
On the first pass, to get the size I am using instances of the FileInfo
class. On the second pass, to copy I am using System.IO File.Copy.

Any suggestions for improvement?


Have a look at
http://khsw.blogspot.com/2006/03/cop...-progress.html
I might give you some ideas I hope.

May 5 '06 #6
http://www.experts-exchange.com/Prog..._21085332.html

contains a completely managed example I did a while ago for someone using
VB.NET, I built work objects along the way so it only did a single pass
which gains quite a bit of speed.

Cheers,

Greg
<vo*********@yahoo.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...

jo*********@topscene.com schreef:
On the first pass, to get the size I am using instances of the FileInfo
class. On the second pass, to copy I am using System.IO File.Copy.

Any suggestions for improvement?


Have a look at
http://khsw.blogspot.com/2006/03/cop...-progress.html
I might give you some ideas I hope.

May 6 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Rosa | last post by:
Hi, I'm trying to clear the TIF on Windows XP programmatically with the below code. This code works fine on any folder but the TIF. For some reason the atEnd() statements always defaults to true...
4
by: Egil Hansen | last post by:
Hi all Do C# and .net have some way to monitor a folder in Windows XP/Windows 2000. I want to mirror the content of the folder, including subfolders (if any exsists) to another place, and I want...
5
by: Robertico | last post by:
Is it possible to upload a complete folder including the subfolders using PHP ? Regards, Robertico
3
by: TyBreaker | last post by:
I have a vbscript which returns the folder size of any folder instantly by referring to Folder.Size. I don't need any iteration or recursion through the subfolders, adding together individual file...
0
by: saratchev | last post by:
Hi all i write a script to syncronize a web folder with a normal one. I want to copy all the files from the normal folder to the web folder. How can a reference the web folder? I have already...
1
by: 7effrey | last post by:
Does anyone have a script that can count the number of files in a folder + subfolders and add it together?
2
by: pbrown | last post by:
Hey All, My problem appears to be pretty simple. I need a way of listing all the folders that exist in a certain directory. By all the folders, I mean ALL the folders; any file folder that exists...
0
by: Chuck Anderson | last post by:
I'm trying to come with a good organization plan for the Apache, Php, MySQL development software on my home PC and am wondering what sort of folder structure others may have come up with that seems...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.