Thread: FileTime???

    #1
  1. Some day I will be a Lambda!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Location
    NJ
    Posts
    18
    Rep Power
    0

    Question FileTime???


    Question:

    I have a program that parses through a directory and gathers information. I'm now trying to trim the parse time down, it takes about 130 seconds to parse 10 gigs on a PIII 600 with 256 RAM. I can cut the time in almost half if I remove the file time functionality. I'm getting the Create, Last Viewed, and Last Modified times of each and every file on the system. Below I have included some code that I just ripped out of my program. I modified it a little just to make it look right. I have enclosed it so that I can show the logic that I'm using. If anyone has any idea of how I can accomplish this task a little more efficient I would be very grateful.

    Code:
    	TCHAR *szPath;		// The path of the folder / directory
    	TCHAR szCurDirPath[400];
    	TCHAR szTemp[5];
    	TCHAR szDate[10];
    	sprintf(szCurDirPath, "%s*.*", szPath);
    
    	hFind = FindFirstFile(szCurDirPath, &data);
    
    	data.ftCreationTime
    	if ( FileTimeToSystemTime(&data.ftCreationTime, &stCreate) != 0 )
    		ConvertFileTime(sCreateDate, stCreate);
    
    	_itoa(stCreate.wMonth, szTemp, 10);
    	sprintf(szDate, "%s-", szTemp);
    	_itoa(stCreate.wDay, szTemp, 10);
    	sprintf(szDate, "%s-", szTemp);
    	_itoa(stCreate.wYear, szTemp, 10);
    	sprintf(szDate, szTemp);
    
    	printf("%s\n", szDate);
    Thank you
    Eric
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,648
    Rep Power
    4248
    Why not just use sprintf() once and avoid using all the _itoa calls.
    As a bonus, you can also get rid of szTemp, if you write your code something like this:
    Code:
    if ( FileTimeToSystemTime(&data.ftCreationTime, &stCreate) != 0 )
         sprintf(szDate, "%d-%d-%d", stCreate.wMonth, stCreate.wDay, stCreate.wYear);
    
    printf("%s\n", szDate);
    Hope this helps!
  4. #3
  5. Some day I will be a Lambda!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Location
    NJ
    Posts
    18
    Rep Power
    0
    As always - You are the Man

    I'll post back and let you know if this helps.

    Thanks
    Eric
  6. #4
  7. Some day I will be a Lambda!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Location
    NJ
    Posts
    18
    Rep Power
    0
    Scorpions4ever

    That modification added 10 seconds on the scan time.
    I'll reboot and see if it's becouse of other software running.

    Eric

    - - After the reboot the run time was almost the same as before the modification.
    Last edited by Beans4You; October 24th, 2002 at 08:13 PM.
  8. #5
  9. Some day I will be a Lambda!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Location
    NJ
    Posts
    18
    Rep Power
    0
    Still doing research trying to figure this one out...

    Now I have not used any real MFC programming and I'm a little scarred of it, but I found this function CTimeSpan which looks like it might be able to help me. This function can return the total number of days and hopefully remove allot of unnecessary conversions that I'm doing. I'm thinking something like: (FileTime_TotalDays - SystemTime_TotalDays) = number of days since {last view, modified, accessed}.

    Can this be done? And if it can, does anyone know how to change filetime to CTimeSpan? Also, this program is just a normal C++ command line program, what changes will I need to implement to use an MFC function?

    Eric

IMN logo majestic logo threadwatch logo seochat tools logo