Linux C 創(chuàng)建目錄函數(shù)mkdir相關(guān)_第1頁
全文預(yù)覽已結(jié)束

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、linux c 創(chuàng)建目錄函數(shù)mkdir相關(guān)i.linux c 創(chuàng)建名目函數(shù)的mode設(shè)置問題函數(shù)原型:ilude sys/.h int mkdir(const char *path, mode_t mode);參數(shù):path是名目名mode是名目權(quán)限返回值:返回0 表示勝利, 返回 -1表示錯(cuò)誤,并且會(huì)設(shè)置errno值。mode模式位:mode 表示新名目的權(quán)限,可以取以下值:s_irusrs_ireads_iwusrs_iwrites_ixusrs_iexecs_irwxuthis is equivalent to (s_irusr | s_iwusr | s_ixusr).s_irgrpr

2、ead peission bit for the group owner of the . ually 040.s_iwgrpwrite permission bit for the group owner of the file. usually 020.s_ixgrpexee or search permission bit for the group owner of the file. usually 010.s_irwxgthis is equivalent to (s_irgrp | s_iwgrp | s_ixgrp).s_irothread permission bit for

3、 other users. usually 04.s_iwothwrite permission bit for other users. usually 02.s_ixothexecute or search permission bit for other users. usually 01.s_irwxothis is equivalent to (s_iroth | s_iwoth | s_ixoth).s_isuidthis is the -user-id on ecute bit, usually 04000. see how change persona.s_isgidthis

4、is the set-group-id on execute bit, usually 02000. see how change persona.s_isvtxthis is the sticky bit, usually 01000.例子:include sys/types.h include sys/stat.h int status;status = mkdir("/home/newdir", s_irwxu | s_irwxg | s_iroth | s_ixoth);這樣就創(chuàng)建了一個(gè)newdir名目,權(quán)限通過 -al 查看為drwxr-xr-x跟用linuxmk

5、dir創(chuàng)建的名目權(quán)限位全都。ii. linux下c語言創(chuàng)建多級名目int createdir(const char *spathname) char dirname256; sy(dirname, spathname); int i,len = strlen(dirname); if(dirnamelen-1!='/') str(dirname, "/"); len = strlen(dirname); for(i=1; i i+) if(dirnamei='/') dirnamei = 0; if( access(dirname, null

6、)!=0 ) if(mkdir(dirname, 0755)=-1) perror("mkdir error"); return -1; dirnamei = '/' return 0; iii.linux c 編程:創(chuàng)建一個(gè)線程,監(jiān)視某個(gè)名目,一旦名目里浮現(xiàn)新的文件,就將文件轉(zhuǎn)移到指定的名目里去。/*頭文件*/define srcpath "sath/"define dstpath "dstpath/"int movefile() dir *dir; struct dirent *dt; file *fp1,*fp2

7、; char filename1256,filename2256; char buf1024; int readsize,size; if(dir = opendir(srcpath) = null) printf("opendir %s errorn",srcpath); return -1; memset(filename1,0,sizeof(filename1); strcpy(filename1,srcpath); memset(filename2,0,sizeof(filename2); strcpy(filename2,dstpath); while(1) wh

8、ile(dt = reair(dir) != null) if(str(dt- d_name,".")=0|strcmp(dt- d_name,".")=0) continue; /假如這個(gè)名目里 還有名目,可以在這加推斷 /這里假設(shè)初始為空名目 strcat(filename1,dt- d_name); strcat(filename2,dt- d_name); /假如進(jìn)程資源較少可以挺直用指令 fp1 = fopen(filename1,"rb"); if(fp1=null) printf("open %s fail /

9、n",filename1); return -1; fp2 = fopen(filename2,"wb"); if(fp2=null) printf("open %s failed /n",filename2); fclose(fp1); return -1; while(readsize = fread(buf,sizeof(buf),1,fp1) 0) /total += readsize; memset(buf,0,sizeof(buf); writesize = fwrite(buf,sizeof(buf),1,fp2); if(writesize!=readsize) printf("write error"); return -2; fclose(fp1); fclose(fp2); fclose(fp1); fclose(fp2

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論