Path: utzoo!mnetor!uunet!husc6!cmcl2!brl-adm!adm!drears@ARDEC.arpa From: drears@ARDEC.arpa (FSAC) Newsgroups: comp.unix.wizards Subject: Re: HELP! File status checking in C Message-ID: <10877@brl-adm.ARPA> Date: 16 Dec 87 16:03:49 GMT Sender: news@brl-adm.ARPA Lines: 53 MIke Chinni writes: MIKE>HELP! MIKE> MIKE> I am in the process of converting a bourne-shell script into C. To do this MIKE>I need to know how to do the following in C: MIKE> 1) Check whether a directory exists MIKE> 2) Given two files: filea and fileb MIKE> Check if filea has been modified more recently than fileb MIKE> MIKE> Mike ChinniYou can do both with the stat(2) call. Stat returns a structure like : struct stat { dev_t st_dev; ino_t st_ino; u_short st_mode; short st_nlink; short st_uid; short st_gid; dev_t st_rdev; off_t st_size; time_t st_atime; int st_spare1; time_t st_mtime; int st_spare2; time_t st_ctime; int st_spare3; long st_blksize; long st_blocks; long st_spare4[2]; }; If st_mode has bits S_IFDIR then it is a directory. To answer the question about modifed the st_atime, st_mtime, and st_ctime fields will let you know depending if you are looking for access, modification, or inode modification time. It returns a value of -1 if it fails or 0 if it is good. Give me a call if (X6639) you need working examples. I have some old programs on ardec-ac4 that does this. Dennis ------------------------------------------------------------ ARPA: drears@ardec.ac4 UUCP: ...!uunet!drears@ARDEC.arpa #if all else fails AT&T: 201-724-6639 Snailmail: Box 210, Wharton, NJ 07885 ------------------------------------------------------------