|
|
| C Programming Faqs: Frequently Asked Questions (ISBN: 0201845199) |
 |
List Price: $34.99
Our Price: $34.99
Used Price: $23.64
Release Date: January, 1996
Manufacturer: Addison-Wesley Pub Co (Paperback)
Sales Rank: 81,838
Author: Steve Summit, Deborah Lafferty
|
More Info
|
|
|
Check Directory
|
2001-11-10 18:49:59
|
| |
c
|
|
|
|
|
Category: source:c:files
|
|
Description: Tests a file to see if it's a directory
|
|
Platform: unix
|
|
Author: detour
|
|
Viewed: 4762
|
|
Rating: 4.4/5 (13 votes)
|
|
|
| If you have any questions about
this piece of code or still need help, try posting your question on the forum. |
/* checkfile.c written by detour@metalshell.com
*
* simple function to check for a directory
*
* http://www.metalshell.com/
*
*/
#include <stdio.h>
#include <sys/stat.h>
int isDir(const char *dname);
int main(int argc, char *argv[]) {
if (argc != 2) {
printf("Usage: %s directory name\n", argv[0]);
exit(0);
}
if(isDir(argv[1])) {
printf("%s is a directory.\n", argv[1]);
}
return 0;
}
int isDir(const char *dname) {
struct stat sbuf;
if (lstat(dname, &sbuf) == -1) {
fprintf(stderr, "lstat() Failed.\n");
return 0;
}
if(S_ISDIR(sbuf.st_mode)) {
return 1;
}
return 0;
}
|
|
|