how to get information about a file

This is a discussion on how to get information about a file within the C++ Programming forums, part of the General Programming Boards category; Hi All Is there an easy way to get information about a file, like size, modification date, permissions, etc ? ...

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    20

    how to get information about a file

    Hi All

    Is there an easy way to get information about a file, like size, modification date, permissions, etc ?

    Thnx in advance
    LuCa

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    You're stuck doing it one of two ways:

    1) O/S specific way.
    2) Faking it by calling other programs that does it.

    For an example for #2, you could call system("dir >> dump.log") for Windows. You would then open and read through dump.log and parse the info to get what you want. It's not the best way of doing it, and it's limited.

    File size can be determined simply by opening the file and moving to the end of the file.

    For O/S specific methods, it obviously depends upon what your O/S is.

  3. #3
    Registered User
    Join Date
    Dec 2006
    Posts
    20
    In my case I'm using Linux and Unix.

    Any suggestion about documentation for these kind of things would be very useful!!

    LuCa

  4. #4
    Registered User
    Join Date
    May 2006
    Posts
    903
    Quote Originally Posted by MacGyver View Post
    You're stuck doing it one of two ways:

    1) O/S specific way.
    2) Faking it by calling other programs that does it.

    For an example for #2, you could call system("dir >> dump.log") for Windows. You would then open and read through dump.log and parse the info to get what you want. It's not the best way of doing it, and it's limited.

    File size can be determined simply by opening the file and moving to the end of the file.

    For O/S specific methods, it obviously depends upon what your O/S is.
    system() is evil. Someone could have replaced cmd.exe with a malicious program and calling system() would launch that malicious program.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,824
    > Any suggestion about documentation for these kind of things would be very useful!!
    opendir() readdir() closedir() and stat()
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User
    Join Date
    Dec 2006
    Posts
    20
    thnx a lot, that will get me started!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 05:27 PM
  2. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 01:36 PM
  3. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 05:54 PM
  4. Error when loading 3ds file
    By The Wazaa in forum C++ Programming
    Replies: 6
    Last Post: 01-24-2006, 08:27 AM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 05:10 PM

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