강좌 & 팁
글 수 2,412
2014.02.22 09:05:40 (*.211.8.120)
66215
윈도우 프로그래밍 개발툴 델파이에서는 하위 디렉토리까지 만들어서
전체 디렉토리를 만들어 주는 ForceDirectories()라는 함수가 있습니다.
예를 들어 '/tmp/src/test/doc'을 인수로 넘기면 /tmp부터 src, test, doc
디렉토리 모두 만들어 줍니다. ForceDirectories() 함수를 gcc용 함수인
force_directory()로 만들어 보았습니다.
void force_directory( char *a_dirc){
char buff[1024];
int sz_dirc;
int ndx;
sz_dirc = strlen( a_dirc);
for ( ndx = 1; ndx < sz_dirc; ndx++){
if ( '/' == a_dirc[ndx]){
a_dirc[ndx] = '\0';
sprintf( buff, "%s", a_dirc);
if ( 0 != access( buff, F_OK)){
mkdir( buff, 0777);
}
a_dirc[ndx] = '/';
}
}
if ( 0 != access( a_dirc, F_OK)){
mkdir( a_dirc, 0777);
}
}


