소켓을 이용한 특정 폴더의 파일 이름 전송시 질문이요
글쓴이: pooh311 / 작성시간: 일, 2005/06/26 - 9:51오후
일단 소스 먼저요~~
server 소스..
while ((pent=readdir(pdir)) != '\0'){ //client에 보내줌
stat(pent->d_name, &st);
if (S_ISDIR(st.st_mode)) {
printf("%s\n", pent->d_name);
pent->d_name[strlen(pent->d_name)+1]='\0';
pent->d_name[strlen(pent->d_name)]='/';
}
write(clnt_sd, pent->d_name, BUFSIZE);
}
write(clnt_sd, "end", BUFSIZE); //client에 파일명 전송이 끝났다는 메시지
closedir(pdir);
client 소스
while(len=read(sd, d_name, BUFSIZE) > 0 ) { //server로 부터 받은 파일 이름들 출력
if(!strcmp(d_name, "end")) {
printf("\n\n");
break;
} //file_name전송 완료를 나타내는 'end'전송시 무한반복 종료
if(!strcmp(d_name, "./")||!strcmp(d_name, "../")) continue; //'.'이나 '..' 전송시 무시
else {
printf("%-15s", d_name); i++;
if (i==4) {
printf("\n");
i=0;
}
} //file_name 출력
}
이렇게 디렉토리는 뒤에 '/'표시를 하도록 해서 일반 파일과 디렉토리를 구분해서 표현 하려고 하는데요
어떤 파일은 위에 '/'들어가고 어떤건 안들어가고..
파일이면서 뒤에 '/'가 들어간 것들에 특별한 연관성도 찾을수 없고..
위 소스에서 잘못 적용한 부분이 있는지..
Forums:


댓글 달기