\u4e00\uff0e\u7a0b\u5e8f\u6982\u8ff0\u5b8c\u6210\u7684\u4efb\u52a1<\/p>\n
1.mypwd\u5217\u4e3e\u5f53\u524d\u76ee\u5f55\u7684\u540d\u79f0\u3002<\/p>\n
2.mychdir\u6539\u53d8\u5f53\u524d\u76ee\u5f55\u3002<\/p>\n
3.mymkdir\u65b0\u5efa\u4e00\u4e2a\u76ee\u5f55<\/p>\n
4.myrmdir\u5220\u6389\u6587\u4ef6\u5939<\/p>\n
5.exit\u9000\u51fa\u547d\u4ee4<\/a>\u7c7b\u5e93\u3002<\/p>\n
6.myrename\u5c06\u6587\u4ef6\u6216\u6587\u4ef6\u5939\u91cd\u547d\u540d\u3002<\/p>\n
7.mycp\u590d\u5236\u5f53\u524d\u5df2\u5b58\u5728\u7684\u6587\u4ef6\u3002<\/p>\n
1.mydate\u663e\u793a\u4e0e\u8bbe\u7f6e\u7cfb\u7edf\u7684\u65e5\u671f\u548c\u65f6\u95f4\u3002<\/p>\n
11.mycd\u5207\u6362\u76ee\u5f55<\/p>\n
\u9047\u89c1\u7684\u56f0\u96be\u53ca\u89e3\u51b3\u7684\u95ee\u9898<\/p>\n
\u4e8c\uff0e\u6982\u5ff5\u539f\u7406<\/p>\n
\u672c\u6b21\u64cd\u4f5c\u7cfb\u7edf\u8bfe\u7a0b\u8bbe\u8ba1\u4f7f\u7528\u7684\u8bed\u8a00\u4e3aC++\uff0c\u5305\u542b\u7684\u5934\u6587\u4ef6\u5927\u591a\u662fLinux<\/a>\u4e0bc\u7684\u51fd\u6570\u5e93\u3002\u901a\u8fc7\u8c03\u7528\u76f8\u5173\u7684\u51fd\u6570\u5e93\u6765\u5b9e\u73b0\u6a21\u62dfshell\u547d\u4ee4\u64cd\u4f5c\u3002\u4e0b\u8fb9\u662f\u5bf9\u4e00\u4e9b\u6982\u5ff5\u539f\u7406\u7684\u8bf4\u660e\uff1a<\/p>\n
\u6e90\u7a0b\u5e8f\u5305\u542b\u7684\u90e8\u4efd\u5934\u6587\u4ef6<\/p>\n
#include\/\/gettimeoftime\/settimeofday\u7684\u51fd\u6570\n#include\/\/\u5305\u542b\u83b7\u53d6\/\u8f6c\u6362\u65f6\u95f4\u7684\u51fd\u6570\n#include\/\/\u4e3b\u8981\u7528\u4e8e\u4e00\u4e9b\u6807\u51c6\u8f93\u5165\u8f93\u51fa\uff1acin,cout\u64cd\u4f5c\n#include\/\/\u6807\u51c6C++\u51fd\u6570\u5e93\uff0c\u4e3b\u8981\u7528\u4e8e\u5b57\u7b26\u4e32\u5904\u7406\n#include\/\/\u57fa\u672c\u7cfb\u7edf\u6570\u636e\u7c7b\u578b\n#include\/\/\u6587\u4ef6\u72b6\u6001\n#include\/\/\u6587\u4ef6\u64cd\u4f5c\u51fd\u6570\n#include\/\/\u6587\u4ef6\u63a7\u5236\n#include\/\/\u6587\u4ef6\u6811\u6f2b\u6e38\n#include\n#include\n#include\n#include\n#include\n#include\n<\/code><\/pre>\n<\/p>\n\u4ee5\u4e0a\u662f\u6574\u4e2a\u6e90\u7a0b\u5e8f\u6d89\u53ca\u5230\u7684\u4e00\u4e9b\u51fd\u6570\u5934\u6587\u4ef6<\/p>\n
2.\u51fd\u6570\u6982\u5ff5\u8bf4\u660e<\/p>\n
\u4ee5\u4e0b\u662f\u5bf9\u7a0b\u5e8f\u8c03\u7528Linuxc\u51fd\u6570\u5e93\u7684\u65b9\u5f0f\u8bf4\u660e\uff1a<\/p>\n
(1).\u8c03\u7528getcwd()\u51fd\u6570<\/p>\n
\u51fd\u6570\u539f\u578b\uff1achar*getcwd(char*buf,size_tsize);<\/p>\n
\u51fd\u6570\u8bf4\u660e\uff1agetcwd()\u4f1a\u5c06\u5f53\u524d\u7684\u5de5\u4f5c\u76ee\u5f55\u7edd\u5bf9\u8def\u5f84\u590d\u5236\u5230\u53c2\u6570buf\u6240\u6307\u7684\u663e\u5b58\u7a7a\u95f4\uff0c\u53c2\u6570size\u4e3abuf\u7684\u7a7a\u95f4\u5927\u5c0f\u3002\u5728\u8c03\u7528\u6b64\u51fd\u6570\u65f6\uff0cbuf\u6240\u6307\u7684\u663e\u5b58\u7a7a\u95f4\u8981\u8db3\u591f\u5927\uff0c\u82e5\u5de5\u4f5c\u76ee\u5f55\u7edd\u5bf9\u8def\u5f84\u7684\u5b57\u7b26\u4e32\u539a\u5ea6\u8d85\u8fc7\u53c2\u6570size\u5927\u5c0f\uff0c\u5219\u56de\u503cNULL\uff0cerrno\u7684\u503c\u5219\u4e3aERANGE\u3002\u5982\u679c\u53c2\u6570buf\u4e3aNULL\uff0cgetcwd()\u4f1a\u4f9d\u53c2\u6570size\u7684\u5927\u5c0f\u624b\u52a8\u914d\u7f6e\u663e\u5b58(\u4f7f\u7528malloc())\uff0c\u5047\u5982\u53c2\u6570size\u4e5f\u4e3a0\uff0c\u5219getcwd()\u4f1a\u4f9d\u5de5\u4f5c\u76ee\u5f55\u7edd\u5bf9\u8def\u5f84\u7684\u5b57\u7b26\u4e32\u7a0b\u5ea6\u6765\u51b3\u5b9a\u6240\u914d\u7f6e\u7684\u663e\u5b58\u5927\u5c0f\uff0c\u8fdb\u7a0b\u53ef\u4ee5\u5728\u4f7f\u7528\u5b8c\u6b64\u5b57\u7b26\u4e32\u540e\u501f\u52a9free()\u6765\u91ca\u653e\u6b64\u7a7a\u95f4\u3002<\/p>\n
\u8fd4\u56de\u503c\uff1a\u6267\u884c\u6210\u529f\u5219\u5c06\u7ed3\u679c\u590d\u5236\u5230\u53c2\u6570buf\u6240\u6307\u7684\u663e\u5b58\u7a7a\u95f4\uff0c\u6216\u662f\u8fd4\u56de\u624b\u52a8\u914d\u7f6e\u7684\u5b57\u7b26\u4e32\u8868\u9488\u3002\u5931\u8d25\u8fd4\u56deNULL\uff0c\u9519\u8bef\u4ee3\u7801\u5b58\u4e8eerrno\u3002<\/p>\n
(2).\u8c03\u7528opendir()\u51fd\u6570<\/p>\n
\u51fd\u6570\u539f\u578b\uff1aDIR*opendir(constchar*name);<\/p>\n
\u51fd\u6570\u8bf4\u660e\uff1aopendir()\u62ff\u6765\u6253\u5f00\u53c2\u6570name\u6307\u5b9a\u7684\u76ee\u5f55\uff0c\u5e76\u8fd4\u56deDIR\u5f62\u6001\u7684\u76ee\u5f55\u6d41\uff0c\u548copen()\u7c7b\u4f3c\uff0c\u63a5\u51fa\u6765\u5bf9\u76ee\u5f55\u7684\u8bfb\u53d6\u548c\u641c\u7d22\u90fd\u8981\u4f7f\u7528\u6b64\u8fd4\u56de\u503c\u3002<\/p>\n
\u8fd4\u56de\u503c\uff1a\u6210\u529f\u5219\u8fd4\u56deDIR\u578b\u6001\u7684\u76ee\u5f55\u6d41\uff0c\u6253\u5f00\u5931\u8d25\u5219\u8fd4\u56deNULL\u3002<\/p>\n
(3).\u8c03\u7528readdir()\u51fd\u6570<\/p>\n
\u51fd\u6570\u539f\u578b\uff1astructdirent*readdir(DIR*dir);<\/p>\n
\u51fd\u6570\u8bf4\u660e\uff1areaddir()\u8fd4\u56de\u53c2\u6570dir\u76ee\u5f55\u6d41\u7684\u4e0b\u4e2a\u76ee\u5f55\u6b65\u5165\u70b9\u3002<\/p>\n
\u7ed3\u6784dirent\u5b9a\u4e49\u5982\u4e0b<\/p>\n
\n
struct dirent\n{\nino_t d_ino;\nff_t d_off;\nsigned short int d_reclen;\nunsigned char d_type;\nhar d_name[256;\n};\n<\/code><\/pre>\n<\/p>\nd_ino\u6b64\u76ee\u5f55\u6b65\u5165\u70b9\u7684inoded_off\u76ee\u5f55\u6587\u4ef6\u5f00\u5934\u81f3\u6b64\u76ee\u5f55\u6b65\u5165\u70b9\u7684\u4f4d\u79fbd_reclen_name\u7684\u5bbd\u5ea6\uff0c\u4e0d\u5305\u542bNULL\u5b57\u7b26d_typed_name\u6240\u6307\u7684\u6587\u4ef6\u7c7b\u578bd_name\u6587\u4ef6\u540d\u8fd4\u56de\u503c\uff1a\u6210\u529f\u5219\u8fd4\u56de\u4e0b\u4e2a\u76ee\u5f55\u6b65\u5165\u70b9\u3002\u6709\u9519\u8bef\u53d1\u751f\u6216\u8bfb\u53d6\u5230\u76ee\u5f55\u6587\u4ef6\u5c3e\u5219\u8fd4\u56deNULL\u3002\u9644\u52a0\u8bf4\u660e\uff1aEBADF\u53c2\u6570dir\u4e3a\u65e0\u6548\u7684\u76ee\u5f55\u6d41\u3002<\/p>\n
(4).\u8c03\u7528closedir()\u51fd\u6570<\/p>\n
\u51fd\u6570\u539f\u578b\uff1a*intclosedir(DIRdir);<\/p>\n
\u51fd\u6570\u8bf4\u660e\uff1aclosedir()\u5173\u6389\u53c2\u6570dir\u6240\u6307\u7684\u76ee\u5f55\u6d41\u3002<\/p>\n
\u8fd4\u56de\u503c\uff1a\u5173\u6389\u6210\u529f\u5219\u8fd4\u56de0\uff0c\u5931\u8d25\u8fd4\u56de-1\uff0c\u9519\u8bef\u7f18\u7531\u5b58\u4e8eerrno\u4e2d\u3002<\/p>\n
(5).\u8c03\u7528chdir()\u51fd\u6570<\/p>\n
\u51fd\u6570\u539f\u578b\uff1aintchdir(constchar*path);<\/p>\n
\u51fd\u6570\u8bf4\u660e\uff1achdir()\u62ff\u6765\u5c06\u5f53\u524d\u7684\u5de5\u4f5c\u76ee\u5f55\u6539\u53d8\u6210\u4ee5\u53c2\u6570path\u6240\u6307\u7684\u76ee\u5f55\u3002<\/p>\n
\u8fd4\u56de\u503c\uff1a\u6267\u884c\u6210\u529f\u8fd4\u56de0\uff0c\u5931\u8d25\u8fd4\u56de-1\uff1b<\/p>\n
(6).\u8c03\u7528mkdir()\u51fd\u6570<\/p>\n
\u51fd\u6570\u539f\u578b\uff1a*intmkdir(constcharpathname,mode_tmode);<\/p>\n
\u51fd\u6570\u8bf4\u660e\uff1amkdir()\u51fd\u6570\u4ee5mode\u65b9\u6cd5\u521b\u5efa\u4e00\u4e2a\u4ee5\u53c2\u6570pathname\u547d\u540d\u7684\u76ee\u5f55\uff0cmode\u5b9a\u4e49\u65b0\u521b\u5efa\u76ee\u5f55\u7684\u6743\u9650\u3002<\/p>\n
\u8fd4\u56de\u503c\uff1a\u82e5\u76ee\u5f55\u521b\u5efa\u6210\u529f\uff0c\u5219\u8fd4\u56de0\uff0c\u5426\u5219\u8fd4\u56de-1\uff1b<\/p>\n
(7).\u8c03\u7528rmdir()\u51fd\u6570<\/p>\n
\u51fd\u6570\u539f\u578b\uff1a*int_rmdir(constchardirname);<\/p>\n
\u51fd\u6570\u8bf4\u660e\uff1armdir\uff08\uff09\u51fd\u6570\u5220\u6389\u4ee5\u53c2\u6570dirname\u4e3a\u547d\u540d\u7684\u76ee\u5f55\u3002<\/p>\n
\u8fd4\u56de\u503c\uff1a\u82e5\u76ee\u5f55\u5220\u6389\u6210\u529f\uff0c\u5219\u8fd4\u56de0\uff0c\u5426\u5219\u8fd4\u56de-1\uff1b<\/p>\n
(8).\u8c03\u7528rename()\u51fd\u6570<\/p>\n
\u51fd\u6570\u539f\u578b\uff1aintrename(constchar*oldpath,constchar*newpath);<\/p>\n
\u51fd\u6570\u8bf4\u660e\uff1arename()\u4f1a\u5c06\u53c2\u6570oldpath\u6240\u6307\u5b9a\u7684\u6587\u4ef6\u540d\u79f0\u6539\u4e3a\u53c2\u6570newpath\u6240\u6307\u7684\u6587\u4ef6\u540d\u79f0\u3002\u82e5newpath\u6240\u6307\u5b9a\u7684\u6587\u4ef6\u5df2\u5b58\u5728\uff0c\u5219\u4f1a\u88ab\u5220\u6389\u3002<\/p>\n
\u8fd4\u56de\u503c\uff1a\u6267\u884c\u6210\u529f\u5219\u8fd4\u56de0\uff0c\u5931\u8d25\u8fd4\u56de-1\u3002<\/p>\n
(9).\u8c03\u7528ftw()\u51fd\u6570<\/p>\n
\u8868\u5934\u6587\u4ef6\uff1a#include<\/p>\n
\u51fd\u6570\u539f\u578b\uff1aintftw(constchar*dir,int(*fn)(constfile,conststructstatsb,intflag),intdepth)<\/p>\n
\u51fd\u6570\u8bf4\u660e\uff1aftw()\u4f1a\u4ece\u53c2\u6570dir\u6307\u5b9a\u7684\u76ee\u5f55\u5f00\u59cb\uff0c\u5f80\u4e0b\u4e00\u5c42\u5c42\u5730\u9012\u5f52\u5f0f\u904d\u5386\u5b50\u76ee\u5f55\u3002ftw()\u4f1a\u4f20\u4e09\u4e2a\u53c2\u6570\u7ed9fn(),\u7b2c\u4e00\u4e2a\u53c2\u6570file\u6307\u5411\u5f53\u65f6\u6240\u5728\u7684\u76ee\u5f55\u8def\u5f84linux vm<\/strong>\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662fsb,\u4e3astat\u7ed3\u6784\u8868\u9488linux\u547d\u4ee4\uff0c\u7b2c\u4e09\u4e2a\u53c2\u6570\u4e3a\u65d7\u6807\uff0c\u6709\u4e0b\u8fb9\u51e0\u79cd\u53ef\u80fd\u503c:<\/p>\n
FTW_F\u901a\u5e38\u6587\u4ef6FTW_D\u76ee\u5f55FTW_DNR\u4e0d\u53ef\u8bfb\u53d6\u7684\u76ee\u5f55\uff0c\u6b64\u76ee\u5f55\u4ee5\u4e0b\u5c06\u4e0d\u88ab\u904d\u5386FTW_SL\u7b26\u53f7\u8054\u63a5FTW_NS\u672a\u80fd\u53d6\u5f97stat\u7ed3\u6784\u6570\u636e\uff0c\u6709\u53ef\u80fd\u662f\u6743\u9650\u95ee\u9898<\/p>\n
\u6700\u540e\u4e00\u4e2a\u53c2\u6570depth\u4ee3\u8868ftw\uff08\uff09\u5728\u8fdb\u884c\u904d\u5386\u76ee\u5f55\u65f6\u540c\u65f6\u6253\u5f00\u7684\u6587\u4ef6\u6570\u3002ftw()\u5728\u904d\u957f\u8fbe\u6bcf\u4e00\u5c42\u76ee\u5f55\u8d77\u7801\u987b\u8981\u4e00\u4e2a\u6587\u4ef6\u63cf\u8ff0\u8bcd\uff0c\u5047\u5982\u904d\u957f\u8fbe\u7528\u5b8c\u4e86depth\u6240\u7ed9\u4e0e\u7684\u9650\u5236\u6570\u91cf\uff0c\u6574\u4e2a\u904d\u5386\u5c06\u56e0\u4e0d\u65ad\u5730\u5173\u6587\u4ef6\u548c\u5f00\u6587\u4ef6\u64cd\u4f5c\u800c\u53d8\u5f97\u5e73\u7f13.<\/p>\n
\u5047\u5982\u8981\u7ed3\u675fftw()\u7684\u904d\u5386\uff0cfn()\u53ea\u9700\u8fd4\u56de\u4e00\u975e\u96f6\u4f4d\u5373\u53ef\uff0c\u6b64\u503c\u540c\u65f6\u4e5f\u4f1a\u662fftw()\u7684\u8fd4\u56de\u503c\u3002\u5426\u5219ftw()\u4f1a\u8bd5\u7740\u8d70\u5b8c\u6240\u6709\u7684\u76ee\u5f55\uff0c\u4e4b\u540e\u8fd4\u56de0.<\/p>\n
\u8fd4\u56de\u503c\uff1a\u904d\u5386\u4e2d\u65ad\u5219\u8fd4\u56defn()\u51fd\u6570\u7684\u8fd4\u56de\u503c\uff0c\u5168\u90e8\u904d\u5386\u5219\u8fd4\u56de0\uff0c\u82e5\u6709\u9519\u8bef\u53d1\u751f\u5219\u8fd4\u56de-1<\/p>\n
\u4e09\uff0e\u8be6\u5c3d\u8bbe\u8ba1\u83dc\u5355\uff1a\u5728\u5217\u51fa\u83dc\u5355\u4e4b\u524d\u5148\u628a\u63a7\u5236\u53f0\u7528clear\u547d\u4ee4\u6d88\u9664\u5185\u5bb9\uff0c\u518d\u8fdb\u884c\u663e\u793a\uff0c\u4ee5\u4fdd\u8bc1\u754c\u9762\u7f8e\u89c2\uff0c\u5728\u83dc\u5355\u7136\u540e\u76f4\u63a5\u8c03\u7528pwd()\u51fd\u6570\u663e\u793a\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\uff0c\u4fbf\u6377\u7528\u6237\u67e5\u770b\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u3002<\/p>\n
\n
system<\/span>(<\/span>\"clear\"<\/span>)<\/span>;<\/span>\n cout<<<\/span>\"~~~~~~~~~\u6b22\u8fce\u6765\u5230lotay\u7684\u547d\u4ee4\u89e3\u91ca\u5668~~~~~~~~~~\"<\/span><<<\/span>endl;<\/span>\n(<\/span>\u7701\u7565\u3002\u3002\u3002\u3002)<\/span>\ncout<<<\/span>\"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\"<\/span><<<\/span>endl;<\/span>\npwd<\/span>(<\/span>)<\/span>;<\/span>\ncout<<<\/span>endl;<\/span>\n<\/code><\/pre>\n<\/p>\n\u663e\u793a\u5f53\u524d\u6240\u5728\u76ee\u5f55\u7684\u8def\u5f84\u540d\uff1a\u8fd9\u4e2a\u529f\u80fd\u5199\u5728pwd()\u51fd\u6570\u4e2d\uff0c\u4f7f\u7528getcwd()\u51fd\u6570\u83b7\u53d6\u5f53\u524d\u76ee\u5f55\u5b58\u8fdbpath\u94fe\u8868\u4e2d\u800c\u4e14\u590d\u5370\u5728\u63a7\u5236\u53f0\u3002<\/p>\n
\n
char<\/span> path[<\/span>100<\/span>]<\/span>;<\/span>\n getcwd<\/span>(<\/span>path,<\/span>100<\/span>)<\/span>;<\/span>\/\/Get path<\/span>\ncout<<<\/span>\"current directory: \"<\/span><<<\/span>path<<<\/span>endl;<\/span>\n<\/code><\/pre>\n<\/p>\n\u5217\u51fa\u6307\u5b9a\u76ee\u5f55\u4e2d\u7684\u6240\u6709\u76ee\u5f55\u53ca\u6587\u4ef6\uff1a\u6b64\u529f\u80fd\u5199\u5728list()\u51fd\u6570\u4e2d\uff0c\u901a\u8fc7\u4f20\u5165\u7684\u76ee\u5f55\uff0c\u7528opendir()\u51fd\u6570\u6253\u5f00\u76ee\u5f55\uff0c\u83b7\u53d6\u76ee\u5f55\u6d41\uff0c\u800c\u4e14\u7528readdir()\u51fd\u6570\u8bfb\u53d6\u6bcf\u4e00\u4e2a\u76ee\u5f55\u8282\u70b9\uff0c\u590d\u5370\u51fa\u4fe1\u606f\uff0c\u6700\u540eclosedir()\u5173\u6389\u8be5\u76ee\u5f55\u3002<\/p>\n
\n
\nDIR*<\/span> d =<\/span> opendir<\/span>(<\/span>dir.<\/span>c_str<\/span>(<\/span>)<\/span>)<\/span>;<\/span>\n if<\/span>(<\/span>d==<\/span>NULL<\/span>)<\/span> {<\/span>\n return<\/span> false;<\/span>\n }<\/span> else<\/span> {<\/span>\n\tstruct<\/span> dirent<\/span> *<\/span>dirent;<\/span>\n while<\/span>(<\/span>dirent=<\/span>readdir<\/span>(<\/span>d)<\/span>)<\/span> {<\/span>\n\t cout<<<\/span>\" \"<\/span><<<\/span>dirent-><\/span>d_name\uff1b\n\t}<\/span>\n\tclosedir<\/span>(<\/span>d)<\/span>;<\/span>\ncout<<<\/span>endl;<\/span>\n return<\/span> true;<\/span>\n}<\/span>\n<\/code><\/pre>\n<\/p>\n\u6539\u53d8\u5f53\u524d\u76ee\u5f55\uff1a\u4f7f\u7528chdir()\u51fd\u6570\u6539\u53d8\u5f53\u524d\u6253\u5f00\u7684\u5de5\u4f5c\u76ee\u5f55\uff0c\u8fd4\u56de0\u65f6\uff0c\u6539\u53d8\u6210\u529f\uff0cchdir()\u51fd\u6570\u8fd4\u56detrue\uff0c\u5426\u5219\u8fd4\u56defalse\u3002<\/p>\n
\n
if<\/span>(<\/span>chdir<\/span>(<\/span>path.<\/span>c_str<\/span>(<\/span>)<\/span>)<\/span>==<\/span>0<\/span>)<\/span> {<\/span>\n return<\/span> true;<\/span>\n }<\/span> else<\/span> {<\/span>\n return<\/span> false;<\/span>\n}<\/span>\n<\/code><\/pre>\n<\/p>\n\u65b0\u5efa\u76ee\u5f55\uff1a\u5728\u51fd\u6570makedir()\u4e2d\u8c03\u7528\u7cfb\u7edf\u7684mkdir\u51fd\u6570\u521b\u5efa\u6307\u5b9a\u76ee\u5f55\u540d\u7684\u76ee\u5f55\uff0c\u5f53\u8fd4\u56de0\u65f6\u521b\u5efa\u6210\u529f\uff0cmakedir()\u51fd\u6570\u8fd4\u56detrue\uff0c\u5426\u5219\u8fd4\u56defalse\uff0c\u521b\u5efa\u7684\u76ee\u5f55\u901a\u5e38\u5177\u6709\u6240\u6709\u6743\u9650\u3002<\/p>\n
\n
if<\/span>(<\/span>mkdir<\/span>(<\/span>dir.<\/span>c_str<\/span>(<\/span>)<\/span>,<\/span> S_IRWXU |<\/span> S_IRWXG |<\/span> S_IROTH |<\/span> S_IXOTH)<\/span>==<\/span>0<\/span>)<\/span> {<\/span>\n return<\/span> true;<\/span>\n }<\/span> else<\/span> {<\/span>\n return<\/span> false;<\/span>\n}<\/span>\n<\/code><\/pre>\n<\/p>\n\u5220\u6389\u76ee\u5f55\uff1a\u5728deldir()\u4e2d\u8c03\u7528rmdir\u51fd\u6570\u5220\u6389\u6307\u5b9a\u76ee\u5f55\uff0c\u8fd4\u56de0\u65f6\u5220\u6389\u6210\u529f\uff0cdeldir()\u51fd\u6570\u8fd4\u56detrue\uff0c\u5426\u5219\u8fd4\u56defalse\u3002<\/p>\n
\n
if<\/span>(<\/span>rmdir<\/span>(<\/span>dir.<\/span>c_str<\/span>(<\/span>)<\/span>)<\/span>==<\/span>0<\/span>)<\/span> {<\/span>\n return<\/span> true;<\/span>\n }<\/span> else<\/span> {<\/span>\n return<\/span> false;<\/span>\n}<\/span>\n<\/code><\/pre>\n<\/p>\n\u91cd\u547d\u540d\uff1a\u5728rename()\u51fd\u6570\u4e2d\u8c03\u7528C\u4e2d\u7684\u6807\u51c6\u51fd\u6570rename\uff0c\u5c06\u65e7\u7684\u76ee\u5f55\u6216\u6587\u4ef6\u540d\u6539\u4e3a\u65b0\u7684\u76ee\u5f55\u6216\u6587\u4ef6\u540d\uff0c\u5f53\u8fd4\u56de0\u65f6\uff0c\u91cd\u547d\u540d\u6210\u529f\uff0crename()\u51fd\u6570\u8fd4\u56detrue\uff0c\u5426\u5219\u8fd4\u56defalse\u3002<\/p>\n
\n
if<\/span>(<\/span>rename<\/span>(<\/span>lastname.<\/span>c_str<\/span>(<\/span>)<\/span>,<\/span>newname.<\/span>c_str<\/span>(<\/span>)<\/span>)<\/span>==<\/span>0<\/span>)<\/span> {<\/span>\n return<\/span> true;<\/span>\n }<\/span> else<\/span> {<\/span>\n return<\/span> false;<\/span>\n}<\/span>\n<\/code><\/pre>\n<\/p>\n\u590d\u5236\u6587\u4ef6\uff1a\u5148\u5224\u522b\u6587\u4ef6\u662f\u5426\u5b58\u5728\uff0c\u82e5\u5b58\u5728\u5219\u5224\u5b9a\u76ee\u6807\u6587\u4ef6\u662f\u5426\u5b58\u5728\uff0c\u5982\u679c\u65e9\u5df2\u5b58\u5728\u8fd9\u4e48\u4fbf\u5728\u539f\u5148\u7684\u6587\u4ef6\u540d\u5b50\u540e\u7f00\u52a0\u4e0a(1)\u518d\u590d\u5236\uff0c\u52a0\u5165\u4e0d\u5b58\u5728\u5219\u76f4\u63a5\u590d\u5236\uff0c\u590d\u5236\u7684\u5f62\u5f0f\u662f\u5148\u8c03\u7528read()\u51fd\u6570\u4ece\u6e90\u6587\u4ef6\u8bfb\u51fa\u5185\u5bb9\u5b58\u8fdbbuf\u94fe\u8868\uff0c\u63a5\u7740\u8c03\u7528write()\u51fd\u6570\u5c06\u5185\u5bb9\u5199\u8fdb\u76ee\u6807\u6587\u4ef6\u3002<\/p>\n
\n
int<\/span> fo1,<\/span>fo2;<\/span>\n char<\/span> buf[<\/span>1024<\/span>]<\/span>;<\/span>\n fo1=<\/span>open<\/span>(<\/span>existname.<\/span>c_str<\/span>(<\/span>)<\/span>,<\/span>O_RDONLY)<\/span>;<\/span>\n if<\/span>(<\/span>fo1==<\/span>-<\/span>1<\/span>)<\/span> {<\/span>\n\t\n\t return<\/span> false;<\/span>\n }<\/span> else<\/span> {<\/span>\n\tfo2=<\/span>open<\/span>(<\/span>newname.<\/span>c_str<\/span>(<\/span>)<\/span>,<\/span>O_RDONLY)<\/span>;<\/span>\n\tif<\/span>(<\/span>fo2!=<\/span>-<\/span>1<\/span>)<\/span> {<\/span>\n\t int<\/span> i;<\/span>\n\t cout<<<\/span>\"Overwrite original file??\"<\/span><<<\/span>endl;<\/span>\n\t cout<<<\/span>