Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,384 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,112 people online right now. Registration is fast and FREE... Join Now!




Folder File Size

 
Reply to this topicStart new topic

Folder File Size, Folder File Size

Inter
7 Oct, 2006 - 12:47 PM
Post #1

New D.I.C Head
*

Joined: 7 Oct, 2006
Posts: 5


My Contributions
Hi, i got an little question im stuck on.

How can i get the size of an folder?
Do i need to loop all the files in the folder somehow?, if so how?

Best Regards
/Inter
User is offlineProfile CardPM
+Quote Post

gregoryH
RE: Folder File Size
7 Oct, 2006 - 09:51 PM
Post #2

D.I.C Regular
Group Icon

Joined: 4 Oct, 2006
Posts: 417


Dream Kudos: 50
My Contributions
Hi

First:
Which C++ compiler are you using?

Second:
Do you want to use the std library, WIN32 API or MFC/VCL?

There isn't a third question, so its not the inquisition....

Regardless of the compiler, this is the sort of problem that can be solved in either a recursive or procedural manner.

Talk to me
User is offlineProfile CardPM
+Quote Post

Xing
RE: Folder File Size
7 Oct, 2006 - 09:56 PM
Post #3

D.I.C Addict
Group Icon

Joined: 22 Jul, 2006
Posts: 723



Thanked: 2 times
Dream Kudos: 1575
My Contributions
OS? Language- C or C++? Compiler?
User is offlineProfile CardPM
+Quote Post

gregoryH
RE: Folder File Size
7 Oct, 2006 - 10:29 PM
Post #4

D.I.C Regular
Group Icon

Joined: 4 Oct, 2006
Posts: 417


Dream Kudos: 50
My Contributions
ok - now its three questions....
User is offlineProfile CardPM
+Quote Post

Inter
RE: Folder File Size
8 Oct, 2006 - 09:05 AM
Post #5

New D.I.C Head
*

Joined: 7 Oct, 2006
Posts: 5


My Contributions
thanks for reply guys

I use MVC++ 6.0
I have Windows XP Pro
Will code it in WinAPI C++

Best Regards Inter
User is offlineProfile CardPM
+Quote Post

Xing
RE: Folder File Size
8 Oct, 2006 - 10:15 AM
Post #6

D.I.C Addict
Group Icon

Joined: 22 Jul, 2006
Posts: 723



Thanked: 2 times
Dream Kudos: 1575
My Contributions
You can use GetFileSize() which needs a handle to folder or open file.
User is offlineProfile CardPM
+Quote Post

violent_crimson
RE: Folder File Size
8 Oct, 2006 - 05:49 PM
Post #7

New D.I.C Head
*

Joined: 31 Aug, 2006
Posts: 36


My Contributions
http://msdn.microsoft.com/library/default....getfilesize.asp
User is offlineProfile CardPM
+Quote Post

Inter
RE: Folder File Size
9 Oct, 2006 - 06:49 AM
Post #8

New D.I.C Head
*

Joined: 7 Oct, 2006
Posts: 5


My Contributions
hi thx for reply.

I still having trouble to get my folder as handle, and if i try with CreateFile, to get the folder as handle and use GetFileSize on that handle, i get result -1?

Best Regards Inter
User is offlineProfile CardPM
+Quote Post

Xing
RE: Folder File Size
9 Oct, 2006 - 07:03 AM
Post #9

D.I.C Addict
Group Icon

Joined: 22 Jul, 2006
Posts: 723



Thanked: 2 times
Dream Kudos: 1575
My Contributions
and your code is?
User is offlineProfile CardPM
+Quote Post

Inter
RE: Folder File Size
10 Oct, 2006 - 10:15 AM
Post #10

New D.I.C Head
*

Joined: 7 Oct, 2006
Posts: 5


My Contributions
Here is the code


CODE
HANDLE hnd_folder = CreateFile("folder1",GENERIC_READ,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
DWORD size = GetFileSize(hnd_folder,NULL);


thanks

/Inter
User is offlineProfile CardPM
+Quote Post

born2c0de
RE: Folder File Size
11 Oct, 2006 - 08:44 AM
Post #11

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 3,935



Thanked: 34 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
That is because folder1 is being created as a file, not a folder....
I get the result as 0..and not -1.
User is offlineProfile CardPM
+Quote Post

Inter
RE: Folder File Size
25 Oct, 2006 - 05:32 AM
Post #12

New D.I.C Head
*

Joined: 7 Oct, 2006
Posts: 5


My Contributions
Hi again.
Cant get this working...
Can anyone paste me a code snippet?
thx Inter
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/5/08 02:05AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month