2009-04-24 22:15

[C語言] 取得目錄名稱路徑(dirname)

dirname

#include <libgen.h>

int main(){
char W_path1[] = "E:\\test" ;
char W_path2[] = "E:\\Program\\clear\\ape-06\\Debug" ;
char W_path3[] = "E:\\Program\\clear\\.metadata\\.plugins\\org" ;

dirname(W_path1);
printf("%s\n",W_path1);
// E:\

dirname(W_path2);
printf("%s\n",W_path2);
// E:\Program\clear\ape-06

dirname(W_path3);
printf("%s\n",W_path3);
// E:\Program\clear\.metadata\.plugins

char L_path1[] = "/test" ;
char L_path2[] = "/Program/clear/ape-06/Debug" ;
char L_path3[] = "/Program/clear/.metadata/.plugins/org" ;

dirname(L_path1);
printf("%s\n",L_path1);
// /

dirname(L_path2);
printf("%s\n",L_path2);
// /Program/clear/ape-06

dirname(L_path3);
printf("%s\n",L_path3);
// /Program/clear/.metadata/.plugins


_getch();
return 0;
}



參考來源:
<libgen.h>

0 回應: