SCANDIR
Section: ¸®´ª½º ÇÁ·Î±×·¡¸Ó ¸Å´º¾ó (3)
Updated: 1996³â 4¿ù 11ÀÏ
Index
Return to Main Contents
À̸§
scandir, alphasort - µð·ºÅ丮¿¡¼ ÇØ´ç Ç׸ñÀ» Á¶»çÇÑ´Ù
»ç¿ë¹ý
#include <dirent.h>
int scandir(const char *dir, struct dirent ***namelist,
- int (*select)(const struct dirent *),
int (*compar)(const struct dirent **, const struct dirent **));
int alphasort(const struct dirent **a, const struct dirent **b);
¼³¸í
scandir() ÇÔ¼ö´Â °¢ µð·ºÅ丮 Ç׸ñ¿¡ ´ëÇØ select()¸¦ È£ÃâÇÏ¸é¼ dir µð·ºÅ丮¸¦ Á¶»çÇÑ´Ù. select()¿¡¼ 0ÀÌ ¾Æ´Ñ °ªÀ» ¹ÝȯÇÑ Ç׸ñµéÀº malloc()À» ÅëÇØ ÇÒ´çµÈ ¹®ÀÚ¿¿¡ ÀúÀåµÇ°í, ºñ±³ ÇÔ¼ö compar()¸¦ »ç¿ëÇÑ
qsort()¿¡ ÀÇÇØ Á¤·ÄµÇ°í, malloc()¸¦ ÅëÇØ ÇÒ´çµÈ namelist
¹è¿¿¡ ¸ð¾ÆÁø´Ù.
select°¡ NULLÀÌ¸é ¸ðµç Ç׸ñÀÌ ¼±ÅõȴÙ.
alphasort() ÇÔ¼ö´Â µð·ºÅ丮 Ç׸ñµéÀ» ¾ËÆĺª ¼ø¼·Î Á¤·ÄÇϱâ À§ÇØ
scandir() ÇÔ¼öÀÇ ºñ±³ ÇÔ¼ö·Î »ç¿ëµÉ ¼ö ÀÖ´Ù. ±× ÇÔ¼öÀÇ ÀÎÀÚ´Â ºñ±³ÇÒ µÎ
°³ÀÇ µð·ºÅ丮 Ç׸ñ a¿Í bÀÌ´Ù.
¹Ýȯ°ª
scandir() ÇÔ¼ö´Â ¼±ÅÃµÈ µð·ºÅ丮 Ç׸ñÀÇ °³¼ö¸¦ ¶Ç´Â ¿¡·¯°¡ ¹ß»ýÇϸé -1À»
¹ÝȯÇÑ´Ù.
alphasort() ÇÔ¼ö´Â ù¹ø° ÀÎÀÚ°¡ µÎ¹ø° ÀÎÀÚº¸´Ù À۰ųª, °°°Å³ª, Å©°Å³ª¿¡
µû¶ó °¢°¢ 0 º¸´Ù À۰ųª, °°°Å³ª, Å« Á¤¼ö¸¦ ¹ÝȯÇÑ´Ù.
¿¡·¯
- ENOMEM
-
¼öÇàÀ» Çϱâ À§ÇÑ ¸Þ¸ð¸® ºÎÁ·ÇÏ´Ù.
ȣȯ
BSD 4.3
¿¹Á¦
/* ÇöÀç µð·ºÅ丮ÀÇ ÆÄÀÏÀ» ¿ª¼øÀ¸·Î Ãâ·ÂÇÑ´Ù */
#include <dirent.h>
main(){
struct dirent **namelist;
int n;
n = scandir(".", &namelist, 0, alphasort);
if (n < 0)
perror("scandir");
else {
while(n--) {
printf("%s\n", namelist[n]->d_name);
free(namelist[n]);
}
free(namelist);
}
}
°ü·Ã Ç׸ñ
opendir(3),
readdir(3),
closedir(3),
rewinddir(3),
telldir(3),
seekdir(3).
¿ªÀÚ
ÀÓÁ¾±Õ <hermes44@secsm.org>, 2001³â 6¿ù 28ÀÏ
Index
- À̸§
-
- »ç¿ë¹ý
-
- ¼³¸í
-
- ¹Ýȯ°ª
-
- ¿¡·¯
-
- ȣȯ
-
- ¿¹Á¦
-
- °ü·Ã Ç׸ñ
-
- ¿ªÀÚ
-
This document was created by
man2html,
using the manual pages.
Time: 08:07:01 GMT, March 25, 2004