Log in:
Register Now! It's FREE!
Members click here to Sign In!

News
RECENT ANNOUNCEMENTS
Post new topic

C program - file sizes in unix / windows

RealPoor.com » RealPoor General Talk » Dead Geeks Society
 
 
Author
 
 
Message
 
Posted: 02/11/05 - 17:07
Report abuse 
RealPoor Guru
Overon
Joined: 14 Oct 2002
Posts: 3315
 
Hey!

My TAs are asian so I'm gunna ask here just in case the email i sent goes unanswered..

My homework assignment is basically a command line program that will find the size of files and folders

if its fed a folder on command line, it will have to recursively go through that folder and all files and subfolders to find the total size of the main folder ... (kind of like when you right click a folder in windows and go to properties and it lists the size)

I need to program it for a windows and a unix environment


EDIT:

ok i have it working perfectly for windows but im having some really f****d up trouble in unix .. i found out how to do it in unix but for some reason when i use my recursive function to go through directories it doesnt recognize a directory as a directory and fails and does weird shit ... (using stat)

i took a look at here http://www.unix.com/archive/index.php/t-8899.html and am using basically their code, altered a bit, and adding stat and using a recursive function


i doubt at this point anyone can help me .. but i dunno .. ill at least post it


EDIT:---------------

f**k it i got it working heh

Last edited by Overon on 02/12/05 - 02:38; edited 2 times in total


Reply with quote
Posted: 02/11/05 - 17:49
Report abuse 
RealPoor Jedi
Occulis
Joined: 11 Oct 2002
Posts: 13299
 
Start with 'man 2 stat' and read everything associated with it.


Reply with quote
Posted: 02/11/05 - 18:38
Report abuse 
RealPoor Guru
Overon
Joined: 14 Oct 2002
Posts: 3315
 
Occulis wrote:
Start with 'man 2 stat' and read everything associated with it.


already read man stat

lemme check man 2.....

same thing ..


still dont know how to get info on files within a directory without knowing the file name...


for instance in windows theres FindFirstFile and FindNextFile to find files within a directory ...


Reply with quote
Posted: 02/11/05 - 18:42
Report abuse 
RealPoor Guru
Mogling
Joined: 29 Dec 2002
Posts: 2446
 
couldn't you feed a list of the files into an array? I only did some basic unix scripting and no C programing in a unix envrioment, so im talking out my a*s right now.


Reply with quote
Posted: 02/11/05 - 18:45
Report abuse 
RealPoor Guru
Overon
Joined: 14 Oct 2002
Posts: 3315
 
Mogling wrote:
couldn't you feed a list of the files into an array? I only did some basic unix scripting and no C programing in a unix envrioment, so im talking out my a*s right now.


list of files?

and if there is a list of files why would i need to put them into another list structure?


Reply with quote
Posted: 02/11/05 - 18:48
Report abuse 
RealPoor Jedi
Occulis
Joined: 11 Oct 2002
Posts: 13299
 
If you read every bit of documentation associated with man stat, you'd be an expert. Reading a 4 page manual entry isn't going to do jack for you. I suggested it as a starting point.


Reply with quote
Posted: 02/11/05 - 18:56
Report abuse 
RealPoor Guru
Overon
Joined: 14 Oct 2002
Posts: 3315
 
Occulis wrote:
If you read every bit of documentation associated with man stat, you'd be an expert. Reading a 4 page manual entry isn't going to do jack for you. I suggested it as a starting point.


stat doesnt look like it can give me information about files in a directory without the name of the file


am i wrong? i cant even think of how it would work if the * character worked with it


Reply with quote
Posted: 02/12/05 - 01:52
Report abuse 
RealPoor Guru
Overon
Joined: 14 Oct 2002
Posts: 3315
 
bump for the update


Reply with quote
Posted: 02/12/05 - 02:34
Report abuse 
RealPoor Sensei
gotissues68
Joined: 21 Aug 2003
Posts: 1868
 
rather then use stat why not use something like a for() struct? I'm not sure there's something like that in C, I'd have to dig my book out and check. But I'm sure you can do some type of loop and put the contents into an array and iterate through them if need be. I know in bash on a unix box you can do:

for file in dir
do <some action>
done;


Reply with quote
Posted: 02/12/05 - 02:38
Report abuse 
RealPoor Guru
Overon
Joined: 14 Oct 2002
Posts: 3315
 
just got it working

weird error

oh well its fixed now


Reply with quote

Post new topic
 
MY NAVIGATOR
 
 
Newsletter
 

Subscribe to FREE monthly RealPoor.com newsletter.

RealPoor.com » RealPoor General Talk » Dead Geeks Society
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum