list size of files in directory

This is a discussion on list size of files in directory within the C Programming forums, part of the General Programming Boards category; Im not sure how to print the size of each file in this directory? any ideas? the only way i ...

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    24

    list size of files in directory

    Im not sure how to print the size of each file in this directory?
    any ideas?

    the only way i know is using ftell, which im not sure if i can use it in this situation.

    Code:
    #include <dirent.h>
    #include <stdio.h>
    #include <conio.h>
    #include <string.h>
    
    int main(void)
    {
        DIR *d;
        struct dirent *dir;
        char *folder = "C:\\j\\ftp\\home\\movies";
    
        int MB = 1048576;
        long size;
    
        d = opendir(folder);
    
        if(d)
        {
            while((dir = readdir(d)) != NULL)
            {
                if(strcmp(dir->d_name, ".") != 0 && strcmp(dir->d_name, "..") != 0)
                {
                 //print size here
                }
            }
    
            closedir(d);
        }
    
        getch();
    
        return 0;
    }

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,265
    What OS?

  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,265
    Actually, from your code it looks like you are using windows. In that case, use the functions FindFirstFile() and FindNextFile() .
    The returned WIN32_FIND_DATA structure contains the file size.

  4. #4
    Registered User
    Join Date
    Sep 2003
    Posts
    24
    Windows XP pro SP1 Borland C++ Biulder 3

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sorting linked list please help with CODE
    By scarlet00014 in forum C Programming
    Replies: 3
    Last Post: 09-28-2008, 12:24 AM
  2. deleting a node in linked list
    By BoneXXX in forum C Programming
    Replies: 18
    Last Post: 12-17-2007, 12:30 PM
  3. Reverse function for linked list
    By Brigs76 in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2006, 11:01 AM
  4. Error with a vector
    By Tropicalia in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2006, 08:45 PM
  5. How can I traverse a huffman tree
    By carrja99 in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2003, 06:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21