Thread: Retreiving File create/modify date

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    5

    Retreiving File create/modify date

    Hi,

    I want to retreive the file create / modify date for a bunch of text files.

    Anyone know any C/C++ code to acheive this?

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    If using Windows, look up the GetFileTime() function, otherwise look up the stat() function.

  3. #3
    If its related directly to windows programming
    then this could make your life easier :

    Code:
    #include <windows.h>
    using namespace std;
    
    int main()
    {
         HANDLE hFind;
         WIN32_FIND_DATA FindData;
         char line1[255] = "SomeDirectory\\Somefile.someextention";
    
    /*
         after specifying you directory, to do all the text files in the dir
         use the file name *.txt, to do all the files use *.*
         Ex.  "c:\\windows\\*.exe" will read all of the exe files
         in the windows folder.
         Ex. "c:\\windows\\*.*"  will read every file in the windows
         directory.
    
    */
       
         hFind = FindFirstFile(line1, &FindData); //Find first file
    
        while (FindNextFile(hFind, &FindData))  //Find Next File
        {
              /*
              Do something here
              Ex. using cout << FindData.ftCreationTime << endl;
              will display the creation time of the current file.
              */
              
        }
        FindClose(hFind);
    
    /*  //Options specifically for what your asking for.
         FindData.ftCreationTime
         FindData.ftLastAccessTime
         FindData.ftLastWriteTime
    */
    
        return 0;
    }
    If you have any questions fee lfree to pm me, i put this together
    real quick so might have made some errors.

  4. #4
    Registered User
    Join Date
    Sep 2004
    Posts
    5
    Thanks - Managed to write this code for visual C++ compiler. I now need to use this info to create a series of windows directories?

    #include <stdlib.h>
    #include <stdio.h>
    #include <io.h>
    #include <time.h>
    #include <conio.h>
    int main(void)

    {

    char buf1[80];
    time_t filecreate;
    struct tm *ptr;
    struct _finddata_t c_file;
    long hfile;

    if ((hfile = _findfirst("D:\\*.c",&c_file)) == 1L)
    printf("a");

    else
    {
    printf("%-12s %.24s % 9ld\n",c_file.name,ctime(&(c_file.time_write)),c_f ile.size);
    filecreate = ctime(&(c_file.time_write));





    }
    _findclose(hfile);


    }
    Last edited by super_stripey; 09-21-2004 at 07:37 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  3. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  5. Hmm....help me take a look at this: File Encryptor
    By heljy in forum C Programming
    Replies: 3
    Last Post: 03-23-2002, 10:57 AM