home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / filedtm.zip / filedtm.c next >
C/C++ Source or Header  |  1998-10-30  |  4KB  |  125 lines

  1. /*  filedtm.c
  2.  
  3.     This code segment illustrates the file system "Date Last Accessed",
  4.     "Creation Date", and "Date Last Written".
  5.  
  6.     The "Date Last Accessed" value can be useful for locating stale or
  7.     unused files, especially on large LAN file storage systems where
  8.     additional disk space may be needed.
  9.  
  10. */
  11.  
  12. /* (c) Copyright IBM Corp. 1998  All rights reserved.
  13.  
  14. This sample program is owned by International Business Machines
  15. Corporation or one of its subsidiaries ("IBM") and is copyrighted
  16. and licensed, not sold.
  17.  
  18. You may copy, modify, and distribute this sample program in any
  19. form without payment to IBM,  for any purpose including developing,
  20. using, marketing or distributing programs that include or are
  21. derivative works of the sample program.
  22.  
  23. The sample program is provided to you on an "AS IS" basis, without
  24. warranty of any kind.  IBM HEREBY  EXPRESSLY DISCLAIMS ALL
  25. WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED
  26. TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  27. PARTICULAR PURPOSE.
  28.  
  29. Some jurisdictions do not allow for the exclusion or limitation of
  30. implied warranties, so the above limitations or exclusions may not
  31. apply to you.  IBM shall not be liable for any damages you suffer
  32. as a result of using, modifying or distributing the sample program
  33. or its derivatives.
  34.  
  35. Each copy of any portion of this sample program or any derivative
  36. work,  must include a the above copyright notice and disclaimer of
  37. warranty.
  38. */
  39.  
  40.  
  41. #define INCL_DOSFILEMGR   /* File Manager values */
  42. #define INCL_DOSERRORS    /* Error values */
  43. #include <os2.h>
  44. #include <stdio.h>
  45. #include <stddef.h>
  46. #include <string.h>
  47. #include <stdlib.h>
  48.  
  49. int main(argc, argv, envp)
  50.    int argc;
  51.    char *argv[];
  52.    char *envp[];
  53.   {
  54.     APIRET  rc         = NO_ERROR; /* Return code */
  55.     FILESTATUS PBuff;
  56.     char       FilePath[256];
  57.  
  58.     if (argc == 2)
  59.         {
  60.         strcpy( FilePath, argv[1]);
  61.         }
  62.     else
  63.         {
  64.         printf("Syntax: filedtm <filepathname>\n");
  65.         return 2;
  66.         }
  67.  
  68.     rc = DosQueryPathInfo( FilePath,
  69.                            FIL_STANDARD,
  70.                            &PBuff,
  71.                            sizeof PBuff);
  72.  
  73.     if (NO_ERROR == rc)
  74.         {
  75.         printf(
  76.             "Filename:          %s\n", FilePath);
  77.         /* Note that Creation Date is 0, if file is on a FAT drive */
  78.         printf(
  79.             "Creation Date    = %04u-%02u-%02u %02u:%02u:%02u\n",
  80.             PBuff.fdateCreation.year+1980,
  81.             PBuff.fdateCreation.month,
  82.             PBuff.fdateCreation.day,
  83.             PBuff.ftimeCreation.hours,
  84.             PBuff.ftimeCreation.minutes,
  85.             PBuff.ftimeCreation.twosecs);
  86.         /* Note that Last Access Date is 0, if file is on a FAT drive */
  87.         printf(
  88.             "Last Access Date = %04u-%02u-%02u %02u:%02u:%02u\n",
  89.             PBuff.fdateLastAccess.year+1980,
  90.             PBuff.fdateLastAccess.month,
  91.             PBuff.fdateLastAccess.day,
  92.             PBuff.ftimeLastAccess.hours,
  93.             PBuff.ftimeLastAccess.minutes,
  94.             PBuff.ftimeLastAccess.twosecs);
  95.         printf(
  96.             "Last Write Date  = %04u-%02u-%02u %02u:%02u:%02u\n",
  97.             PBuff.fdateLastWrite.year+1980,
  98.             PBuff.fdateLastWrite.month,
  99.             PBuff.fdateLastWrite.day,
  100.             PBuff.ftimeLastWrite.hours,
  101.             PBuff.ftimeLastWrite.minutes,
  102.             PBuff.ftimeLastWrite.twosecs);
  103.         }
  104.     else
  105.         {
  106.         switch (rc)
  107.           {
  108.             case ERROR_FILE_NOT_FOUND:
  109.                     printf("File Not Found: %s\n", FilePath);
  110.                     break;
  111.             case ERROR_PATH_NOT_FOUND:
  112.                     printf("Invalid Path: %s\n", FilePath);
  113.                     break;
  114.             case ERROR_SHARING_VIOLATION:
  115.                     printf("Sharing Violation: %s\n", FilePath);
  116.                     break;
  117.             default:
  118.                     printf("File Error %u: %s\n", rc, FilePath);
  119.                     break;
  120.           }
  121.         }
  122.  
  123.     return NO_ERROR;
  124.  
  125.  }