{"id":294067,"date":"2024-10-31T12:06:49","date_gmt":"2024-10-31T04:06:49","guid":{"rendered":"https:\/\/gulass.cn\/lcxgswcrwydk.html"},"modified":"2024-10-31T12:06:49","modified_gmt":"2024-10-31T04:06:49","slug":"lcxgswcrwydk","status":"publish","type":"post","link":"https:\/\/gulass.cn\/lcxgswcrwydk.html","title":{"rendered":"linux vm \u7a0b\u5e8f\u6982\u8ff0\uff1a\u5b8c\u6210\u4efb\u52a1\u3001\u9047\u5230\u56f0\u96be\u53ca\u89e3\u51b3\u95ee\u9898"},"content":{"rendered":"

\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

8.myfind\u5728\u6307\u5b9a\u7684\u76ee\u5f55\u67e5\u627e\u6307\u5b9a\u7684\u6587\u4ef6\u6216\u6587\u4ef6\u5939\uff0c\u5e76\u8f93\u51fa\u7edd\u5bf9\u8def\u5f84\u3002<\/p>\n

9.mylist\u5217\u4e3e\u76ee\u5f55\u540d\u4e2d\u5168\u90e8\u7684\u76ee\u5f55\u548c\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

1.\u5b89\u88c5\u7684\u865a\u62df\u673a\u4e0d\u662f\u82f1\u6587\u7684linux vm<\/strong>\uff0c\u6211\u5148\u662f\u5728\u7ec8\u7aef\u8f93\u5165\u201csudoapt-yinstallfcitxfcitx-binfcitx-tablefcitx-table-all\u201d\uff0c\u518d\u8f93\u5165\u201csudoapt-yinstallfcitx-config-gtk\u201d\u5b89\u88c5\u53ef\u89c6\u5316\u914d\u7f6e\u754c\u9762\uff1b\u4e4b\u540e\u7528\u50b2\u6e38\u4e0b\u8f7d\u5b89\u88c5\u641c\u72d7\u8f93\u5165\u6cd5\uff08linux\u724864\u4f4d\uff09\uff0c\u5e76\u5728ubuntu\u8f6f\u4ef6\u4e2d\u5fc3\u5b89\u88c5\uff0c\u518d\u5c06\u8f93\u5165\u6cd5\u6846\u67b6\u6539\u4e3afcitx\uff0c\u5e76\u4e0b\u8f7d\u201clanguagesupport\u201d\u4e2d\u7684chinese\u5305\uff0c\u518d\u5207\u6362\u8f93\u5165\u6cd5\uff0c\u8bbe\u7f6e\u4e3a\u641c\u72d7<\/p>\n

2.\u672a\u80fd\u5b9e\u73b0\u50cf\u4e2d\u5b66\u4e00\u6837\u53ef\u4ee5\u4ece\u684c\u9762\u63a8\u5165\u62d6\u8fdb\u6587\u4ef6\u7684\u529f\u80fd\uff0c\u6211\u5148\u662f\u4e0b\u4e86VMwareTOOL\uff0c\u4e4b\u540e\u5c06\u538b\u7f29\u5305\u653e\u684c\u9762\uff0c\u518d\u6b65\u5165\u7ec8\u7aef\uff0c\u201csudosu\u201d\u8fdb\u5165\u8d85\u7ea7\u7528\u6237\u6a21\u5f0f\uff0c\u518d\u4e00\u6b65\u4e00\u6b65cd\u8bbf\u95ee\u5b89\u88c5\uff0c\u6700\u540e\u91cd\u542f\u5b9e\u73b0<\/p>\n

3.date\u529f\u80fd\u5728\u7f51\u4e0a\u770b\u4e86\u597d\u591a\uff0c\u4f46\u4e0d\u6653\u5f97\u4e3a\u4f55\u7ed3\u5e03\u5149\u6dfb\u52a0\u5c31\u62a5\u9519<\/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

\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>\n

d_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>\"----1 is yes,not 1 is no.\"<\/span>;<\/span>\n\t    cin>><\/span>i;<\/span>\n\t    if<\/span>(<\/span>i!=<\/span>1<\/span>)<\/span> {<\/span>\n\t\tnewname+=<\/span>\"(1)\"<\/span>;<\/span>\n\t     }<\/span>\n\t     close<\/span>(<\/span>fo2)<\/span>;<\/span>\n\t}<\/span>\n        fo2=<\/span>open<\/span>(<\/span>newname.<\/span>c_str<\/span>(<\/span>)<\/span>,<\/span>O_WRONLY|<\/span>O_CREAT,<\/span>S_IRWXU)<\/span>;<\/span>\n\tint<\/span> size =<\/span> read<\/span>(<\/span>fo1,<\/span>buf,<\/span>sizeof<\/span>(<\/span>buf)<\/span>)<\/span>;<\/span>\n\twrite<\/span>(<\/span>fo2,<\/span>buf,<\/span>size)<\/span>;<\/span>\n\tclose<\/span>(<\/span>fo1)<\/span>;<\/span>\n\tclose<\/span>(<\/span>fo2)<\/span>;<\/span>\n\treturn<\/span> true;<\/span>\n}<\/span>\n<\/code><\/pre>\n<\/p>\n

\u67e5\u627e\u6307\u5b9a\u6587\u4ef6\u548c\u76ee\u5f55\uff1a\u901a\u8fc7\u8c03\u7528ftw\u51fd\u6570\u53cd\u5f39\u904d\u5386\u6307\u5b9a\u76ee\u5f55\u4e2d\u7684\u6587\u4ef6\uff0cfn\u662f\u53cd\u5f39\u51fd\u6570\uff0c\u6bcf\u4e00\u6b21\u904d\u5386\u5230\u4e00\u4e2a\u8282\u70b9\uff0cftw\u51fd\u6570\u5c31\u4f1a\u628a\u8282\u70b9\u8def\u5f84\u548c\u8282\u70b9\u4fe1\u606f\u4ee5\u53ca\u7c7b\u578b\u4f20\u5165fn\u51fd\u6570\u4e2d\uff0c\u540c\u65f6\uff0c\u628a\u987b\u8981\u67e5\u627e\u7684\u6587\u4ef6\u540d\u5b50\u4f5c\u4e3a\u5168\u5c40\u53d8\u91cf\uff0c\u5728fn\u4e2d\u5224\u5b9a\u662f\u5426\u5b58\u5728\u800c\u4e14\u8f93\u51fa\u3002<\/p>\n

\n

ftw<\/span>(<\/span>dir.<\/span>c_str<\/span>(<\/span>)<\/span>,<\/span>fn,<\/span>500<\/span>)<\/span>;<\/span>\nint<\/span> fn<\/span>(<\/span>const<\/span> char<\/span> *<\/span>fpath,<\/span> const<\/span> struct<\/span> stat<\/span> *<\/span>st,<\/span> int<\/span> typeflag)<\/span> {<\/span>\n    for<\/span>(<\/span>int<\/span> i=<\/span>strlen<\/span>(<\/span>fpath)<\/span>-<\/span>1<\/span>,<\/span>j=<\/span>file.<\/span>length<\/span>(<\/span>)<\/span>-<\/span>1<\/span>;<\/span>;<\/span>i--<\/span>,<\/span>j--<\/span>)<\/span> {<\/span>\n\tif<\/span>(<\/span>j==<\/span>-<\/span>1<\/span>&&<\/span>fpath[<\/span>i]<\/span>==<\/span>'\/'<\/span>)<\/span> {<\/span>\n\t    cout<<<\/span>\"  \"<\/span><<<\/span>fpath;<\/span>\n\t    if<\/span>(<\/span>typeflag==<\/span>FTW_F)<\/span> cout<<<\/span>\"   FILE\"<\/span><<<\/span>endl;<\/span>\n\t    else<\/span> if<\/span>(<\/span>typeflag==<\/span>FTW_D)<\/span> cout<<<\/span>\"  DIRECTORY\"<\/span><<<\/span>endl;<\/span>\n\t    num++<\/span>;<\/span>\n\t    break<\/span>;<\/span>\n\t}<\/span>\n\tif<\/span>(<\/span>fpath[<\/span>i]<\/span>==<\/span>'\/'<\/span>)<\/span> break<\/span>;<\/span>\n\tif<\/span>(<\/span>j==<\/span>-<\/span>1<\/span>)<\/span> break<\/span>;<\/span>\n\tif<\/span>(<\/span>fpath[<\/span>i]<\/span>!=<\/span>file[<\/span>j]<\/span>)<\/span> {<\/span>\n\t    break<\/span>;<\/span>\n\t}<\/span> \n    }<\/span>\n    return<\/span> 0<\/span>;<\/span>\n}<\/span>\n<\/code><\/pre>\n<\/p>\n

\u9000\u51fa\uff1a\u76f4\u63a5\u5728main\u51fd\u6570\u4e2d\u8fd4\u56de0\u3002\u56db\uff0e\u5b8c\u6210\u60c5\u51b5<\/p>\n

\u5b8c\u6210\u4e86\u6574\u4e2a\u64cd\u4f5c\u7cfb\u7edf\u8bfe\u7a0b\u8bbe\u8ba1\u7684\u547d\u4ee4\u884c\u529f\u80fd\u57fa\u672c\u8981\u6c42\uff1a<\/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\u7c7b\u5e93\u3002<\/p>\n

6.mycp\u590d\u5236\u5f53\u524d\u5df2\u5b58\u5728\u7684\u6587\u4ef6\u3002<\/p>\n

7.mylist\u5217\u4e3e\u76ee\u5f55\u540d\u4e2d\u5168\u90e8\u7684\u76ee\u5f55\u548c\u6587\u4ef6\u3002<\/p>\n

8.mydate\u663e\u793a\u4e0e\u8bbe\u7f6e\u7cfb\u7edf\u7684\u65e5\u671f\u548c\u65f6\u95f4\u3002<\/p>\n

9.mycd\u5207\u6362\u76ee\u5f55<\/p>\n

\u57fa\u672c\u5b8c\u6210\u4e86\u4ee5\u4e0b\u51e0\u4e2a\u6269\u5145\u547d\u4ee4\u7684\u8981\u6c42\uff1a<\/p>\n

1.myrename\u5c06\u6587\u4ef6\u6216\u6587\u4ef6\u5939\u91cd\u547d\u540d\u3002<\/p>\n

2.myfind\u5728\u6307\u5b9a\u7684\u76ee\u5f55\u67e5\u627e\u6307\u5b9a\u7684\u6587\u4ef6\u6216\u6587\u4ef6\u5939\uff0c\u5e76\u8f93\u51fa\u7edd\u5bf9\u8def\u5f84\u3002<\/p>\n

\u901a\u8fc7\u6d4b\u8bd5\uff0c\u4ee5\u4e0a\u6240\u6709\u547d\u4ee4\u90fd\u8fd0\u884c\u6b63\u5e38\u3002\u6574\u4e2a\u7a0b\u5e8f\uff0c\u4ee3\u7801\u5b9e\u73b0\u7b80\u5355\u6e05\u6670\uff0c\u6ca1\u6709\u592a\u590d\u6742\u7684\u7b97\u6cd5\u3002\u57fa\u672c\u4e0a\u5c31\u662f\u5bf9\u51fd\u6570\u7684\u8c03\u7528\u5b9e\u73b0\u3002\u8fd0\u884c\u7ed3\u679c\u53c8\u8f83\u597d\u7684\u63d0\u793a\u4fe1\u606f\uff0c\u65e0\u8bba\u662f\u6210\u529f\u9519\u8bef\u90fd\u63d0\u793a\u76f8\u5e94\u7684\u4fe1\u606f\u3002\u6e90\u4ee3\u7801\u7684\u6ce8\u91ca\u5185\u5bb9\u4e5f\u5341\u5206\u6e05\u6670\uff0c\u4fbf\u6377\u67e5\u770b\u7406\u89e3\u51fd\u6570\u8c03\u7528\u7684\u529f\u80fd\u3002<\/p>\n

\u4e94\uff0e\u4f7f\u7528\u60c5\u51b5<\/p>\n

\u9996\u5148\u6b65\u5165\u547d\u4ee4\u89e3\u91ca\u6743\u754c\u9762<\/p>\n

\u5728\u6b65\u5165\u7a0b\u5e8f\u4f1a\u6709\u83dc\u5355\u53ef\u4f9b\u9009\u62e9\uff0c\u4e00\u5171\u670911\u4e2a\u529f\u80fd\uff0c\u4f46\u662f\u5728\u83dc\u5355\u4e0b\u8fb9\u4f1a\u6709\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u663e\u793a\u5728\u754c\u9762\u4e0a\uff0c\u5982\u53f3\u56fe\uff1a<\/p>\n

\u4fee\u6539\u5f53\u524d\u76ee\u5f55\u7684\u540d\u5b50\uff08\u8f93\u5165\u547d\u4ee42\uff09<\/p>\n

\u65b0\u5efa\u4e00\u4e2a\u76ee\u5f55\uff08\u547d\u4ee43\uff09<\/p>\n

\u5220\u6389\u4e00\u4e2a\u76ee\u5f55\uff08\u547d\u4ee44\uff09<\/p>\n

\u91cc\u9762\u662f\u5b58\u5728\u8be5\u76ee\u5f55\u7684\u60c5\u51b5\uff0c\u4e0b\u8fb9\u662f\u4e0d\u5b58\u5728\u8be5\u76ee\u5f55\u7684\u60c5\u51b5<\/p>\n

\u9000\u51fa\u547d\u4ee4\u7c7b\u5e93\uff08\u547d\u4ee45\uff09<\/p>\n

\u5c06\u6587\u4ef6\u91cd\u547d\u540d\uff08\u547d\u4ee46\uff09<\/p>\n

\u590d\u5236\u65e9\u5df2\u5b58\u5728\u7684\u6587\u4ef6\uff08\u547d\u4ee47\uff09<\/p>\n

\u67e5\u627e\u6587\u4ef6<\/p>\n

\u516d\uff0e\u8bbe\u8ba1\u603b\u7ed3<\/p>\n

\u7ecf\u9a8c\u6559\u8bad<\/p>\n

\u4e00\u5f00\u59cb\u8fd8\u662f\u5e94\u5f53\u597d\u597d\u628avmtools\u88c5\u597d\u7684\uff0c\u8fd9\u6837\u53ef\u4ee5\u8282\u7701\u597d\u591a\u8bd5\u9519\u4ee3\u7801\u7684\u65f6\u95f4\uff0c\u867d\u7136\u6211\u5bf9c\u8bed\u8a00\u548cc++\u6709\u70b9\u6df7\u6dc6\uff0c\u4e0d\u8fc7\u597d\u5728\u5e73\u5e38\u4e0a\u673a\u4e5f\u5e38\u5e38\u6709\u7528c++\u505a\uff0c\u53ea\u8981\u6709\u601d\u8def\u5927\u7ea6\u5c31\u53ef\u4ee5\u505a\u4e0b\u6765\uff0ccsdn\u771f\u662f\u4e2a\u633a\u597d\u7684\u5b66\u4e60\u7f51\u7ad9\uff0c\u5bf9Linux\u6211\u8fd8\u633a\u611f\u5174\u8da3\uff0c\u4ed6\u7684\u754c\u9762UI\u7b80\u5355\u7f8e\u89c2\uff0c\u64cd\u4f5c\u4fbf\u6377\uff0c\u8fd8\u53ef\u4ee5\u5b66\u4e60\u4e00\u4e9b\u547d\u4ee4\u4ee3\u7801linux\u7cfb\u7edf\u547d\u4ee4\uff0c\u89c9\u5f97\u6572\u4ee3\u7801\u7684\u8fc7\u7a0b\u5f88\u4eab\u53d7\uff0c\u4e0d\u8fc7\u5e38\u5e38\u4e00\u9047\u5230Bug\u5c31\u65e0\u4ece\u4e0b\u624b\u4e86\uff0c\u4f46\u662f\u7f51\u4e0a\u7684\u8d44\u6599\u4e5f\u6bd4\u8f83\u96f6\u788e\uff0c\u6211\u5e94\u5f53\u53bb\u56fe\u4e66\u9986\u7cfb\u7edf\u7684\u77a7\u77a7\u9986\u85cf\u8bb2\u89e3linux\u7684\u4e66\u7c4d\u7684\u3002\u56de\u987e\u6574\u4e2a\u8bfe\u8bbe\uff0c\u4e3b\u8981\u662fdate\u54ea\u91cc\u82b1\u4e86\u597d\u591a\u65f6\u95f4\uff0c\u4e0d\u6653\u5f97\u4e3a\u4f55\u7ed3\u6784\u4f53\u52a0\u8fdb\u53bb\u62a5\u9519\uff0c\u6211\u4e0b\u53bb\u518d\u77a7\u77a7\uff0c\u5e0c\u671b\u8fdb\u4e00\u6b65\u63d0\u9ad8\u81ea\u5df1\u7684\u80fd\u529b\u3002\u96be\u7684\u5730\u65b9\u662f\u5047\u5982\u53bb\u7406\u89e3Linuxc\u51fd\u6570\u5e93\u7684\u8c03\u7528\u3002\u987b\u8981\u82b1\u65f6\u95f4\u53bb\u7406\u89e3\u6bcf\u4e00\u4e2a\u51fd\u6570\u7684\u4f5c\u7528\u548c\u76f8\u5173\u53c2\u6570\u7684\u4f5c\u7528\u3002\u521a\u5f00\u59cb\u505a\u7684\u65f6\u4faf\uff0c\u4e5f\u662f\u4e0d\u6653\u5f97\u5982\u4f55\u5f00\u59cb\uff0c\u4e4b\u524d\u628a\u95ee\u9898\u60f3\u5f97\u590d\u6742\u5316\u4e86\uff0c\u540e\u6765\u901a\u8fc7\u4e00\u6b65\u4e00\u6b65\u5b9e\u73b0\u6bcf\u4f4d\u6307\u4ee4\uff0c\u624d\u6e10\u6e10\u627e\u5230\u89e3\u51b3\u7684\u529e\u6cd5\u3002<\/p>\n

\u5b9e\u8df5\u4f53\u4f1a<\/p>\n

\u603b\u7684\u6765\u8bf4\uff0c\u6574\u4e2a\u8bfe\u7a0b\u8bbe\u8ba1\u8fd8\u7b97\u6bd4\u8f83\u987a\u5229\uff0c\u7531\u4e8e\u5bf9Linux\u64cd\u4f5c\u7cfb\u7edf\u63a5\u89e6\u5f97\u5e76\u4e0d\u591a\uff0c\u5bf9\u4e00\u4e9b\u547d\u4ee4\u884c\u7684\u5b9e\u73b0\u8fd8\u4e0d\u600e\u6837\u6e05\u695a\uff0c\u540e\u6765\u901a\u8fc7\u67e5\u9605\u8d44\u6599\uff0c\u53d1\u89c9Linux\u786e\u5b9e\u5341\u5206\u7b80\u7ea6\u597d\u7528\uff0c\u6211\u5341\u5206\u559c\u6b22\u8fd9\u6837\u7684\u7cfb\u7edf\u3002\u957f\u8fbe\u5341\u5929\u7684\u65f6\u95f4\uff0c\u628a\u7a0b\u5e8f\u8bbe\u8ba1\u4e0b\u6765\u4e86\uff0c\u4e5f\u8ba4\u771f\u5199\u4e86\u4e0b\u6b64\u6b21\u7684\u6587\u6863\u3002\u89c9\u5f97\u901a\u8fc7\u4e00\u6bb5\u65f6\u95f4\u7684\u5b66\u4e60\uff0c\u81ea\u5df1\u7684\u7f16\u7a0b\u80fd\u529b\u786e\u5b9e\u53d8\u5f3a\u4e86\uff0c\u4f46\u8fd8\u662f\u6709\u8bb8\u591a\u4e0d\u8db3\u3002\u5728\u7a0b\u5e8f\u8bbe\u8ba1\u8fc7\u7a0b\u4e2d\uff0c\u8981\u5b66\u4f1a\u67e5\u770b\u6587\u6863\uff0c\u7531\u4e8e\u597d\u591a\u6587\u6863\u90fd\u662f\u82f1\u8bed\uff0c\u8fd9\u5c31\u987b\u8981\u82f1\u8bed\u597d\u4e00\u70b9\u3002\u6211\u4e5f\u5728\u514b\u670d\u67e5\u770b\u82f1\u8bed\u6587\u6863\u7684\u969c\u788d\uff0c\u52aa\u529b\u63d0\u9ad8\u81ea\u5df1\u7684\u82f1\u8bed\u9605\u8bfb\u80fd\u529b\u3002\u901a\u8fc7\u6b64\u6b21\u8bfe\u7a0b\u8bbe\u8ba1\uff0c\u4e5f\u8ba9\u81ea\u5df1\u62fe\u8d77\u4e86C++\u8fd9\u95e8\u8bed\u8a00\uff0c\u719f\u6089\u4e86Linux\u73af\u5883\u4e0b\u7684\u4e00\u4e9b\u547d\u4ee4\u64cd\u4f5c\uff0c\u800c\u4e14\u8ba9\u6211\u6709\u4e86\u6781\u5ef6\u5e86\u8da3\u53bb\u7814\u7a76Linux\uff0c\u6211\u5728\u63a5\u51fa\u6765\u7684\u65f6\u95f4\u91cc\u4e5f\u4f1a\u4f7f\u7528\u548c\u5b66\u4e60Linux\u7a0b\u5e8f\u8bbe\u8ba1\u3002\u603b\u7684\u6765\u8bf4\uff0c\u89c9\u5f97\u4e0d\u9519\u3002<\/p>\n

\u4e03\uff0e\u53c2\u8003\u6587\u732e<\/p>\n

[1]\u300a\u6559\u6750\u540d\u79f0\u300b\uff0c\u4e3b\u7f16\uff0c\u51fa\u7248\u793e\uff0c\u51fa\u7248\u65f6\u95f4\uff08\u6559\u6750\uff09<\/p>\n

[2]\u4f5c\u8005.\u6587\u732e\u9898\u540d[J].\u520a\u540d,\u5e74,\u5377(\u671f):\u8d77\u6b62\u9875\u811a.\uff08\u520a\u7269\u8bba\u6587\uff09<\/p>\n

[3]\u4f5c\u8005.\u6587\u732e\u9898\u540d[D].\u51fa\u7248\u5730:\u51fa\u7248\u5355\u4f4d,\u51fa\u7248\u5e74:\u8d77\u6b62\u9875\u811a\uff08\u5b66\u4f4d\u8bba\u6587\uff09<\/p>\n

[4][\u6587\u732e\u7c7b\u578b\/\u8f7d\u4f53\u7c7b\u578b\u6807\u793a]\uff1a[J\/OL]\u7f51\u4e0a\u520a\u7269\u3001[EB\/OL]\u7f51\u4e0a\u7535\u5b50\u516c\u544a\uff08\u7535\u5b50\u6587\u732e\uff09<\/p>\n

[5]\u300aLinux\u7a0b\u5e8f\u8bbe\u8ba1\u7b2c4\u7248\u300b<\/p>\n

[6]\u300aTheGUNCLibraryManual\u300b<\/p>\n

\u4ee3\u7801\u8be6\u60c5\uff1a<\/p>\n

\n

#<\/span>include<\/span><\/span><\/span>\n#<\/span>include<\/span><\/span><\/span>\n#<\/span>include<\/span><\/span><\/span>\n#<\/span>include<\/span><\/span><\/span>\n#<\/span>include<\/span><\/span><\/span>\n#<\/span>include<\/span><\/span><\/span>\n#<\/span>include<\/span><\/span><\/span>\n#<\/span>include<\/span><\/span><\/span>\n#<\/span>include<\/span><\/span><\/span>\n#<\/span>include<\/span><\/span><\/span>\n#<\/span>include<\/span><\/span><\/span>\n#<\/span>include<\/span><\/span><\/span>\n#<\/span>include<\/span><\/span><\/span>\n#<\/span>include<\/span><\/span><\/span>\n#<\/span>include<\/span><\/span>\/\/gettimeoftime\/settimeofday\u7684\u51fd\u6570<\/span><\/span>\n#<\/span>include<\/span><\/span>\/\/\u5305\u542b\u83b7\u53d6\/\u8f6c\u6362\u65f6\u95f4\u7684\u51fd\u6570<\/span><\/span>\nusing namespace std;<\/span>\n\/\/struct tm<\/span>\n\/\/{<\/span>\n\/\/\tint tm_sec;\/\/\u79d2<\/span>\n\/\/\tint tm_year;\/\/\u5e74<\/span>\n\/\/\tint tm_mon;\/\/\u6708<\/span>\n\/\/\tint tm_mday;\/\/\u65e5<\/span>\n\/\/\tint tm_hour;\/\/\u65f6<\/span>\n\/\/\tint tm_min;\/\/\u5206<\/span>\n\/\/\tint tm_sec;\/\/\u79d2<\/span>\n\/\/}<\/span>\n\/\/struct timeval<\/span>\n\/\/{<\/span>\n\/\/\t_time_t tv_sec;<\/span>\n\/\/\t_suseconds_t tv_usec;<\/span>\n\/\/}<\/span>\n\/\/struct timezone<\/span>\n\/\/{<\/span>\n\/\/\tint tz_minuteswest;<\/span>\n\/\/\tint tz_dsttime;<\/span>\n\/\/}<\/span>\nvoid<\/span> pwd<\/span>(<\/span>)<\/span>\n{<\/span>\n\tchar<\/span> path[<\/span>100<\/span>]<\/span>;<\/span>\n\tgetcwd<\/span>(<\/span>path,<\/span>100<\/span>)<\/span>;<\/span>\n\tcout<<<\/span>\"\u5f53\u524d\u76ee\u5f55\"<\/span><<<\/span>path<<<\/span>endl;<\/span>\n}<\/span>\nbool list<\/span>(<\/span>string dir)<\/span>\n{<\/span>\n\tDIR*<\/span> d=<\/span>opendir<\/span>(<\/span>dir.<\/span>c_str<\/span>(<\/span>)<\/span>)<\/span>;<\/span>\n\tif<\/span>(<\/span>d==<\/span>NULL<\/span>)<\/span>\n\t{<\/span>\n\t\treturn<\/span> false;<\/span>\n\t}<\/span>\n\telse<\/span>\n\t{<\/span>\n\t\tstruct<\/span> dirent<\/span> *<\/span>dirent;<\/span>\n\t\twhile<\/span>(<\/span>dirent=<\/span>readdir<\/span>(<\/span>d)<\/span>)<\/span>\n\t\t{<\/span>\n\t\t\tcout<<<\/span>\" \"<\/span><<<\/span>dirent-><\/span>d_name;<\/span>\n\/\/\u6587\u4ef6\u540d\uff0c\u6587\u4ef6\u7c7b\u578b\uff0c\u6587\u4ef6\u540d\u957f<\/span>\n\t\t}<\/span>\n\t\tclosedir<\/span>(<\/span>d)<\/span>;<\/span>\n\t\tcout<<<\/span>endl;<\/span>\n\t\treturn<\/span> true;<\/span>\n\t}<\/span>\n}<\/span>\nbool changedir<\/span>(<\/span>string path)<\/span>\n{<\/span>\n\tif<\/span>(<\/span>chdir<\/span>(<\/span>path.<\/span>c_str<\/span>(<\/span>)<\/span>)<\/span>==<\/span>0<\/span>)<\/span>\n\t{<\/span>\n\t\treturn<\/span> true;<\/span>\n\t}<\/span>\n\telse<\/span>\n\t{<\/span>\n\t\treturn<\/span> false;<\/span>\n\t}<\/span>\n}<\/span>\nbool makedir<\/span>(<\/span>string dir)<\/span>\n{<\/span>\n\tif<\/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>\n\t{<\/span>\n\t\treturn<\/span> true;<\/span>\n\t}<\/span>\n\telse<\/span>\n\t{<\/span>\n\t\treturn<\/span> false;<\/span>\n\t}<\/span>\n}<\/span>\nbool deldir<\/span>(<\/span>string dir)<\/span>\n{<\/span>\n\tif<\/span>(<\/span>rmdir<\/span>(<\/span>dir.<\/span>c_str<\/span>(<\/span>)<\/span>)<\/span>==<\/span>0<\/span>)<\/span>\n\t{<\/span>\n\t\treturn<\/span> true;<\/span>\n\t}<\/span>\n\telse<\/span>\n\t{<\/span>\n\t\treturn<\/span> false;<\/span>\n\t}<\/span>\n}<\/span>\nbool rename<\/span>(<\/span>string lastname,<\/span>string newname)<\/span>{<\/span>\n\tif<\/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>\n\t{<\/span>\n\t\treturn<\/span> true;<\/span>\n\t}<\/span>\n\telse<\/span>\n\t{<\/span>\n\t\treturn<\/span> false;<\/span>\n\t}<\/span>\n}<\/span>\nbool copy<\/span>(<\/span>string existname,<\/span>string newname)<\/span>{<\/span>\n\tint<\/span> fo1,<\/span>fo2;<\/span>\n\tchar<\/span> buf[<\/span>1024<\/span>]<\/span>;<\/span>\n\tfo1=<\/span>open<\/span>(<\/span>existname.<\/span>c_str<\/span>(<\/span>)<\/span>,<\/span>O_RDONLY)<\/span>;<\/span>\n\tif<\/span>(<\/span>fo1==<\/span>-<\/span>1<\/span>)<\/span>\n\t{<\/span>\n\t\treturn<\/span> false;<\/span>\n\t}<\/span>\n\telse<\/span>\n\t{<\/span>\n\t\tfo2=<\/span>open<\/span>(<\/span>newname.<\/span>c_str<\/span>(<\/span>)<\/span>,<\/span>O_RDONLY)<\/span>;<\/span>\n\t\tif<\/span>(<\/span>fo2!=<\/span>-<\/span>1<\/span>)<\/span>\n\t\t{<\/span>\n\t\t\tint<\/span> i;<\/span>\n\t\t\tcout<<<\/span>\"\u662f\u5426\u91cd\u65b0\u4e66\u5199\u539f\u76ee\u5f55 ?\"<\/span><<<\/span>endl;<\/span>\n\t\t\tcout<<<\/span>\"-----1 \u662f,not 1 \u4e0d\u662f.\"<\/span><<<\/span>endl;<\/span>\n\t\t\tcin>><\/span>i;<\/span>\n\t\t\tif<\/span>(<\/span>i!=<\/span>1<\/span>)<\/span>\n\t\t\t{<\/span>\n\t\t\t\tnewname+=<\/span>\"(1)\"<\/span>;<\/span>\n\t\t\t}<\/span>\n\t\t\tclose<\/span>(<\/span>fo2)<\/span>;<\/span>\n\t\t}<\/span>\n\t\tfo2=<\/span>open<\/span>(<\/span>newname.<\/span>c_str<\/span>(<\/span>)<\/span>,<\/span>O_WRONLY|<\/span>O_CREAT,<\/span>S_IRWXU)<\/span>;<\/span>\n\t\tint<\/span> size=<\/span>read<\/span>(<\/span>fo1,<\/span>buf,<\/span>sizeof<\/span>(<\/span>buf)<\/span>)<\/span>;<\/span>\n\t\twrite<\/span>(<\/span>fo2,<\/span>buf,<\/span>size)<\/span>;<\/span>\n\t\tclose<\/span>(<\/span>fo1)<\/span>;<\/span>\n\t\tclose<\/span>(<\/span>fo2)<\/span>;<\/span>\n\t\treturn<\/span> true;<\/span>\n\t}<\/span>\n}<\/span>\nint<\/span> num=<\/span>0<\/span>;<\/span>\nstring file;<\/span>\nint<\/span> fn<\/span>(<\/span>const<\/span> char<\/span> *<\/span>fpath,<\/span>const<\/span> struct<\/span> stat<\/span> *<\/span>st,<\/span>int<\/span> typeflag)<\/span>\n{<\/span>\n\tfor<\/span>(<\/span>int<\/span> i=<\/span>strlen<\/span>(<\/span>fpath)<\/span>-<\/span>1<\/span>,<\/span>j=<\/span>file.<\/span>length<\/span>(<\/span>)<\/span>-<\/span>1<\/span>;<\/span>;<\/span>i--<\/span>,<\/span>j--<\/span>)<\/span>\n\t{<\/span>\n\t\tif<\/span>(<\/span>j==<\/span>-<\/span>1<\/span>&&<\/span>fpath[<\/span>i]<\/span>==<\/span>'\/'<\/span>)<\/span>\n\t\t{<\/span>\n\t\t\tcout<<<\/span>\" \"<\/span><<<\/span>fpath;<\/span>\n\t\t\tif<\/span>(<\/span>typeflag==<\/span>FTW_F)<\/span>cout<<<\/span>\" FILE\"<\/span><<<\/span>endl;<\/span>\n\t\t\telse<\/span> if<\/span>(<\/span>typeflag==<\/span>FTW_D)<\/span>cout<<<\/span>\" DIRECTORY\"<\/span><<<\/span>endl;<\/span>\n\t\t\tnum++<\/span>;<\/span>\n\t\t\tbreak<\/span>;<\/span>\n\t\t}<\/span>\n\t\tif<\/span>(<\/span>fpath[<\/span>i]<\/span>==<\/span>'\/'<\/span>)<\/span>break<\/span>;<\/span>\n\t\tif<\/span>(<\/span>j==<\/span>-<\/span>1<\/span>)<\/span>break<\/span>;<\/span>\n\t\tif<\/span>(<\/span>fpath[<\/span>i]<\/span>!=<\/span>file[<\/span>i]<\/span>)<\/span>\n\t\t{<\/span>\n\t\t\tbreak<\/span>;<\/span>\n\t\t}<\/span>\n\t}<\/span>\n\treturn<\/span> 0<\/span>;<\/span>\n}<\/span>\nbool find<\/span>(<\/span>string dir,<\/span>string filename)<\/span>\n{<\/span>\n\tfile=<\/span>filename;<\/span>\n\tftw<\/span>(<\/span>dir.<\/span>c_str<\/span>(<\/span>)<\/span>,<\/span>fn,<\/span>500<\/span>)<\/span>;<\/span>\n\tif<\/span>(<\/span>num==<\/span>0<\/span>)<\/span>\n\t{<\/span>\n\t\treturn<\/span> false;<\/span>\n\t}<\/span>\n\telse<\/span>\n\t{<\/span>\n\t\treturn<\/span> true;<\/span>\n\t}<\/span>\n}<\/span>\nvoid<\/span> cd<\/span>(<\/span>)<\/span>\n{<\/span>\n\t\/\/char buffer[1024];<\/span>\n\t\/\/FILE *in,*out;<\/span>\n\t\/\/int len;<\/span>\n\t\/\/if((in=fopen(dirname1,\"r\"))==NULL)<\/span>\n\t\/\/{<\/span>\n\t\/\/\tcout<<"\u8fd9\u4e2a\u6587\u4ef6\u65e0\u6cd5\u6253\u5f00"<<endl;<\/span>\n\t\/\/\texit(1);<\/span>\n\t\/\/}<\/span>\n\t\/\/if((out=fopen(dirname2,\"w\"))==NULL)<\/span>\n\t\/\/{<\/span>\n\t\/\/\tcout<<"\u8fd9\u4e2a\u65b0\u6587\u4ef6\u65e0\u6cd5\u6253\u5f00"<<endl;<\/span>\n\t\/\/\texit(1);<\/span>\n\t\/\/}<\/span>\n\t\/\/while((len=fread(buffer,1,1024,in))>0)<\/span>\n\t\/\/{<\/span>\n\t\/\/\tfwrite(buffer,1,len,out);<\/span>\n\t\/\/\tmemset(buffer,0,1024);<\/span>\n\t\/\/}<\/span>\n\t\/\/fclose(out);<\/span>\n\t\/\/fclose(in);<\/span>\n   char<\/span> dirname[<\/span>20<\/span>]<\/span>;<\/span>  \n   cin>><\/span>dirname;<\/span>\n   if<\/span>(<\/span>chdir<\/span>(<\/span>dirname)<\/span> ==<\/span> -<\/span>1<\/span>)<\/span>  \n   {<\/span>  \n      cout<<<\/span>\"\u8fd9\u4e2a\u6587\u4ef6\u4e0d\u5b58\u5728!\"<\/span><<<\/span>endl;<\/span>  \n  \n    }<\/span>  \n    else<\/span>  \n    {<\/span>  \n      cout<<<\/span>\"\u5207\u6362\u6587\u4ef6\u6210\u529f!!!\"<\/span><<<\/span>endl;<\/span>  \n     }<\/span>  \n}<\/span>\n\/\/int alllist(char *dirPath)<\/span>\n\/\/{<\/span>\n\t\/\/DIR *dir=opendir(dirPath);<\/span>\n\t\/\/if(dir==NULL)<\/span>\n\t\/\/{<\/span>\n\t\/\/\tcout<<strerror(errno)<<endl;<\/span>\n\t\/\/\treturn;<\/span>\n\t\/\/}<\/span>\n\t\/\/chdir(dirPath);<\/span>\n\t\/\/struct dirent *ent;<\/span>\n\t\/\/while((ent=readdir(dir))!=NULL)<\/span>\n\t\/\/{<\/span>\n\t\/\/\tif(strcmp(ent->d_name,\".\")==0||strcmp(ent->d_name,\"..\")==0)<\/span>\n\t\/\/\t{<\/span>\n\t\/\/\t\tcontinue;<\/span>\n\t\/\/\t}<\/span>\n\t\/\/\tstruct stat st;<\/span>\n\t\/\/\tstat(ent->d_name,&st);<\/span>\n\t\/\/\tif(S_ISDIR(st.st_mode))<\/span>\n\t\/\/\t{<\/span>\n\t\/\/\t\tgetFileName(ent->d_name);<\/span>\n\t\/\/\t}<\/span>\n\t\/\/\telse<\/span>\n\t\/\/\t{<\/span>\n\t\/\/\t\tcout<d_name<<endl;<\/span>\n\t\/\/\t}<\/span>\n\t\/\/\tclosedir(dir);<\/span>\n\t\/\/\tchdir(\"..\");<\/span>\n\t\/\/}<\/span>\n\/\/}<\/span>\nlong<\/span> gettimesec<\/span>(<\/span>void<\/span>)<\/span>\n{<\/span>\n\tlong<\/span> cursec=<\/span>0<\/span>;<\/span>\n\tstruct<\/span> timeval<\/span> curtimesec;<\/span>\n\tgettimeofday<\/span>(<\/span>&<\/span>curtimesec,<\/span>NULL<\/span>)<\/span>;<\/span>\n\tcursec=<\/span>curtimesec.<\/span>tv_sec;<\/span>\n\treturn<\/span> cursec;<\/span>\n}<\/span>\nvoid<\/span> TimeSet<\/span>(<\/span>int<\/span> year,<\/span>int<\/span> month,<\/span>int<\/span> day,<\/span>int<\/span> hour,<\/span>int<\/span> min,<\/span>int<\/span> sec)<\/span>\n{<\/span>\n\tstruct<\/span> tm<\/span> tptr;<\/span>\n\tstruct<\/span> timeval<\/span> tv;<\/span>\n\ttptr.<\/span>tm_year=<\/span>year+<\/span>1900<\/span>;<\/span>\n\ttptr.<\/span>tm_mon=<\/span>month+<\/span>1<\/span>;<\/span>\n\ttptr.<\/span>tm_mday=<\/span>day;<\/span>\n\ttptr.<\/span>tm_hour=<\/span>hour;<\/span>\n\ttptr.<\/span>tm_min=<\/span>min;<\/span>\n\ttptr.<\/span>tm_sec=<\/span>sec;<\/span>\n\ttv.<\/span>tv_sec=<\/span>mktime<\/span>(<\/span>&<\/span>tptr)<\/span>;<\/span>\n\ttv.<\/span>tv_usec=<\/span>0<\/span>;<\/span>\n\tsettimeofday<\/span>(<\/span>&<\/span>tv,<\/span>NULL<\/span>)<\/span>;<\/span>\n}<\/span>\nvoid<\/span> time<\/span>(<\/span>)<\/span>\n{<\/span>\n\ttime_t<\/span> now;<\/span>\n\t\/\/struct tm *timenow;<\/span>\n\ttime<\/span>(<\/span>&<\/span>now)<\/span>;<\/span>\n\t\/\/timenow=localtime(&now);<\/span>\n\t\/\/cout<<"\u672c\u5730\u65f6\u95f4\u662f\uff1a"<<a style='color:#0000CC;font-size:16px;' sctime(timenow)<<endl;<\/span>\n}<\/span>\nstring datetime<\/span>(<\/span>)<\/span>{<\/span>\n\/\/    time_t now = time(0);\/\/ \u57fa\u4e8e\u5f53\u524d\u7cfb\u7edf\u7684\u5f53\u524d\u65e5\u671f\/\u65f6\u95f4<\/span>\n\/\/    tm *ltm = localtime(&now);<\/span>\n \n\/\/    char iyear[50],imonth[50],iday[50],ihour[50],imin[50],isec[50];<\/span>\n\/\/    sprintf(iyear, \"%d\",1900 + ltm->tm_year );<\/span>\n\/\/    sprintf(imonth, \"d\", 1 + ltm->tm_mon );<\/span>\n\/\/    sprintf(iday, \"d\", ltm->tm_mday );<\/span>\n\/\/    sprintf(ihour, \"d\", ltm->tm_hour );<\/span>\n\/\/    sprintf(imin, \"d\",  ltm->tm_min);<\/span>\n\/\/    sprintf(isec, \"d\",  ltm->tm_sec);<\/span>\n \n\/\/    vector sDate{iyear, imonth, iday};<\/span>\n\/\/    vector sTime{ihour, imin, isec};<\/span>\n\/\/    string myDate = boost::algorithm::join(sDate, \"-\") ;<\/span>\n\/\/    string myTime = boost::algorithm::join(sTime, \":\") ;<\/span>\n\/\/    vector sDateTime{myDate, myTime};<\/span>\n\/\/    string myDateTime = boost::algorithm::join(sDateTime, \" \") ;<\/span>\n\/\/    return myDateTime;<\/span>\n    time_t<\/span> timep;<\/span>\/\/time_t\u8868\u793a\u7684\u65f6\u95f4\u8f6c\u6362\u4e3a\u6ca1\u6709\u7ecf\u8fc7\u65f6\u533a\u8f6c\u6362\u7684UTC\u65f6\u95f4\uff0c\u662f\u4e00\u4e2astruct tm\u7ed3\u6784\u6307\u9488<\/span>\n    time<\/span> (<\/span>&<\/span>timep)<\/span>;<\/span>\/\/\u8c03\u7528time()\u65b9\u6cd5\u83b7\u53d6time_t\u7c7b\u578b\u7684\u5f53\u524d\u65f6\u95f4<\/span>\n    char<\/span> tmp[<\/span>64<\/span>]<\/span>;<\/span>\n    strftime<\/span>(<\/span>tmp,<\/span> sizeof<\/span>(<\/span>tmp)<\/span>,<\/span> \"%Y-%m-%d %H:%M:%S\"<\/span>,<\/span>localtime<\/span>(<\/span>&<\/span>timep)<\/span> )<\/span>;<\/span>\n    \/\/\u8c03\u7528strftime()\u51fd\u6570\u683c\u5f0f\u5316localtime(&timep)\u5e76\u628a\u5b83\u5b58\u5728tmp\u4e2d<\/span>\n    \/\/localtime()\u51fd\u6570\u5c06timep\u7684\u6307\u5206\u89e3\u6210tm\u7ed3\u6784\uff0c\u5e76\u7528\u672c\u5730\u65f6\u533a\u8868\u793a<\/span>\n    puts<\/span>(<\/span>tmp)<\/span>;<\/span>\n}<\/span>\nvoid<\/span> menu<\/span>(<\/span>)<\/span>{<\/span>\n\tsystem<\/span>(<\/span>\"clear\"<\/span>)<\/span>;<\/span>\n\tcout<<<\/span>\"~~~~~~~~~~~~~~~~~~~~~~~~\u6b22\u8fce\u6765\u5230lotay\u7684\u547d\u4ee4\u89e3\u91ca\u5668~~~~~~~~~~~~~~~~~~~~~~~~\"<\/span><<<\/span>endl;<\/span>\n\tcout<<<\/span>\"1.{mypwd}\u5217\u51fa\u5f53\u524d\u76ee\u5f55\u7684\u540d\u79f0\u3002\"<\/span><<<\/span>endl;<\/span>\n\tcout<<<\/span>\"2.{mychdir}\u6539\u53d8\u5f53\u524d\u76ee\u5f55\u3002\"<\/span><<<\/span>endl;<\/span>\n\tcout<<<\/span>\"3.{mymkdir}\u65b0\u5efa\u4e00\u4e2a\u76ee\u5f55\u3002\"<\/span><<<\/span>endl;<\/span>\n\tcout<<<\/span>\"4.{myrmdir}\u5220\u9664\u6587\u4ef6\u5939\u3002\"<\/span><<<\/span>endl;<\/span>\n\tcout<<<\/span>\"5.{exit}\u9000\u51fa\u547d\u4ee4\u89e3\u91ca\u5668\u3002\"<\/span><<<\/span>endl;<\/span>\n\tcout<<<\/span>\"6.{myrename}\u5c06\u6587\u4ef6\u6216\u6587\u4ef6\u5939\u91cd\u547d\u540d\u3002\"<\/span><<<\/span>endl;<\/span>\n\tcout<<<\/span>\"7.{mycp}\u590d\u5236\u5f53\u524d\u5df2\u5b58\u5728\u7684\u6587\u4ef6\u3002\"<\/span><<<\/span>endl;<\/span>\n\tcout<<<\/span>\"8.{myfind}\u5728\u6307\u5b9a\u7684\u76ee\u5f55\u67e5\u627e\u6307\u5b9a\u7684\u6587\u4ef6\u6216\u6587\u4ef6\u5939\uff0c\u5e76\u8f93\u51fa\u7edd\u5bf9\u8def\u5f84\u3002\"<\/span><<<\/span>endl;<\/span>\n\tcout<<<\/span>\"9.{mylist}\u5217\u51fa\u76ee\u5f55\u540d\u4e2d\u5168\u90e8\u7684\u76ee\u5f55\u548c\u6587\u4ef6\u3002\"<\/span><<<\/span>endl;<\/span>\n\tcout<<<\/span>\"10.{mydate}\u663e\u793a\u4e0e\u8bbe\u7f6e\u7cfb\u7edf\u7684\u65e5\u671f\u548c\u65f6\u95f4\u3002\"<\/span><<<\/span>endl;<\/span>\n\tcout<<<\/span>\"11.{mycd}\u5207\u6362\u76ee\u5f55\u3002\"<\/span><<<\/span>endl;<\/span>\n\tcout<<<\/span>\"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\"<\/span><<<\/span>endl;<\/span>\n\tpwd<\/span>(<\/span>)<\/span>;<\/span>\n\tcout<<<\/span>endl;<\/span>\n}<\/span>\nint<\/span> main<\/span>(<\/span>)<\/span>\n{<\/span>\n\/\/struct tm;<\/span>\nsystem<\/span>(<\/span>\"data\"<\/span>)<\/span>;<\/span>\/\/\u672a\u4fee\u6539\u524d\u65f6\u95f4<\/span>\nTimeSet<\/span>(<\/span>2020<\/span>,<\/span>12<\/span>,<\/span>11<\/span>,<\/span>1<\/span>,<\/span>30<\/span>,<\/span>8<\/span>)<\/span>;<\/span>\nsystem<\/span>(<\/span>\"data\"<\/span>)<\/span>;<\/span>\/\/\u4fee\u6539\u540e\u65f6\u95f4<\/span>\nmenu<\/span>(<\/span>)<\/span>;<\/span>\nstring s;<\/span>\nwhile<\/span>(<\/span>1<\/span>)<\/span>{<\/span>\ncout<<<\/span>\"\u8bf7\u8f93\u5165\u83dc\u5355\u6570\u5b57:\"<\/span><<<\/span>endl;<\/span>\ncin>><\/span>s;<\/span>\nif<\/span>(<\/span>s==<\/span>\"1\"<\/span>)<\/span>\n{<\/span>\n\/\/\u5217\u51fa\u5f53\u524d\u76ee\u5f55\u540d<\/span>\n\tmenu<\/span>(<\/span>)<\/span>;<\/span>\n\tcout<<<\/span>\"\u8bf7\u8f93\u5165\u5f53\u524d\u76ee\u5f55:\"<\/span><<<\/span>endl;<\/span>\n\tstring dir;<\/span>\n\tcin>><\/span>dir;<\/span>\n\t\tif<\/span>(<\/span>!<\/span>list<\/span>(<\/span>dir)<\/span>)<\/span>\n\t\t{<\/span>\n\t\t\tcout<<<\/span>\"\u6253\u5f00\u5931\u8d25\/\u6ca1\u6709\u8be5\u76ee\u5f55!\"<\/span><<<\/span>endl;<\/span>\n\t\t}<\/span>\n}<\/span>\nelse<\/span> if<\/span>(<\/span>s==<\/span>\"2\"<\/span>)<\/span>\n{<\/span>\n\/\/\u6539\u53d8\u5f53\u524d\u76ee\u5f55<\/span>\n\tmenu<\/span>(<\/span>)<\/span>;<\/span>\n\tcout<<<\/span>\"\u8bf7\u8f93\u5165\u6307\u5b9a\u7684\u6587\u4ef6\u540d\u6216\u76ee\u5f55\u540d:\"<\/span><<<\/span>endl;<\/span>\n\tstring path;<\/span>\n\tcin>><\/span>path;<\/span>\n\tif<\/span>(<\/span>!<\/span>changedir<\/span>(<\/span>path)<\/span>)<\/span>\n\t{<\/span>\n\t\tcout<<<\/span>\"\u6253\u5f00\u5931\u8d25\/\u8be5\u76ee\u5f55\u4e2d\u4e0d\u5b58\u5728!\"<\/span><<<\/span>endl;<\/span>\n\t}<\/span>\n\telse<\/span>\n\t{<\/span>\n\t\tcout<<<\/span>\"\u5f53\u524d\u6587\u4ef6\u5df2\u66f4\u6539\"<\/span><<<\/span>path<<<\/span>endl;<\/span>\n\t}<\/span>\n}<\/span>\nelse<\/span> if<\/span>(<\/span>s==<\/span>\"3\"<\/span>)<\/span>\n{<\/span>\n\/\/\u65b0\u5efa<\/span>\n\tcout<<<\/span>\"\u8bf7\u8f93\u5165\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\u540d:\"<\/span><<<\/span>endl;<\/span>\n\tstring dir;<\/span>\n\tcin>><\/span>dir;<\/span>\n\tif<\/span>(<\/span>!<\/span>makedir<\/span>(<\/span>dir)<\/span>)<\/span>\n\t{<\/span>\n\t\tcout<<<\/span>\"\u521b\u5efa\u6587\u4ef6\u5931\u8d25!\"<\/span><<<\/span>endl;<\/span>\n\t}<\/span>\n\telse<\/span>\n\t{<\/span>\n\t\tcout<<<\/span>\"\u6587\u4ef6\u521b\u5efa\u6210\u529f\u5566~\"<\/span><<<\/span>endl;<\/span>\n\t}<\/span>\n}<\/span>\nelse<\/span> if<\/span>(<\/span>s==<\/span>\"4\"<\/span>)<\/span>\n{<\/span>\n\/\/\u5220\u9664<\/span>\n\tmenu<\/span>(<\/span>)<\/span>;<\/span>\n\tcout<<<\/span>\"\u8bf7\u8f93\u5165\u4e00\u4e2a\u5df2\u5b58\u5728\u7684\u6587\u4ef6\u540d:\"<\/span><<<\/span>endl;<\/span>\n\tstring dir;<\/span>\n\tcin>><\/span>dir;<\/span>\n\tif<\/span>(<\/span>!<\/span>deldir<\/span>(<\/span>dir)<\/span>)<\/span>\n\t{<\/span>\n\t\tcout<<<\/span>\"\u6587\u4ef6\u4e0d\u5b58\u5728\/\u5220\u9664\u5931\u8d25\"<\/span><<<\/span>endl;<\/span>\n\t}<\/span>\n\telse<\/span>\n\t{<\/span>\n\t\tcout<<<\/span>\"\u6587\u4ef6\u5220\u9664\u6210\u529f\"<\/span><<<\/span>endl;<\/span>\n\t}<\/span>\n}<\/span>\nelse<\/span> if<\/span>(<\/span>s==<\/span>\"5\"<\/span>)<\/span>\n{<\/span>\n\/\/\u9000\u51fa<\/span>\n\tmenu<\/span>(<\/span>)<\/span>;<\/span>\n\tcout<<<\/span>\"\u90a3\u62dc\u62dc\u5566\u5440\uff0c\u6b22\u8fce\u4e0b\u6b21\u518d\u6765\u563b\u563b!\"<\/span><<<\/span>endl;<\/span>\n\treturn<\/span> 0<\/span>;<\/span>\n}<\/span>\nelse<\/span> if<\/span>(<\/span>s==<\/span>\"6\"<\/span>)<\/span>\n{<\/span>\n\/\/\u91cd\u547d\u540d<\/span>\n\tmenu<\/span>(<\/span>)<\/span>;<\/span>\n\tstring lastname,<\/span>newname;<\/span>\n\tcout<<<\/span>\"\u8bf7\u8f93\u5165\u65e7\u7684\u6587\u4ef6\u540d\/\u76ee\u5f55\u540d:\"<\/span><<<\/span>endl;<\/span>\n\tcin>><\/span>lastname;<\/span>\n\tcout<<<\/span>\"\u8bf7\u8f93\u5165\u65b0\u7684\u6587\u4ef6\u540d\/\u76ee\u5f55\u540d:\"<\/span><<<\/span>endl;<\/span>\n\tcin>><\/span>newname;<\/span>\n\tif<\/span>(<\/span>!<\/span>rename<\/span>(<\/span>lastname,<\/span>newname)<\/span>)<\/span>\n\t{<\/span>\n\t\tcout<<<\/span>\"\u91cd\u547d\u540d\u5931\u8d25\u5566\u54e6!\"<\/span><<<\/span>endl;<\/span>\n\t}<\/span>\n\telse<\/span>{<\/span>\n\t\tcout<<<\/span>\"\u8036!\u91cd\u547d\u540d\u6210\u529f\u5566\u5440\uff5e\"<\/span><<<\/span>endl;<\/span>\n\t}<\/span>\n}<\/span>\nelse<\/span> if<\/span>(<\/span>s==<\/span>\"7\"<\/span>)<\/span>\n{<\/span>\/\/\u590d\u5236<\/span>\n\tmenu<\/span>(<\/span>)<\/span>;<\/span>\n\tstring existname,<\/span>newname;<\/span>\n\tcout<<<\/span>\"\u8bf7\u8f93\u5165\u4e00\u4e2a\u5df2\u5b58\u5728\u7684\u6587\u4ef6\u540d\u6216\u76ee\u5f55\u540d:\"<\/span><<<\/span>endl;<\/span>\n\tcin>><\/span>existname;<\/span>\n\tcout<<<\/span>\"\u8bf7\u8f93\u5165\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\u540d\u6216\u76ee\u5f55\u540d\uff08\u7528\u6765\u5b58\u653e\u590d\u5236\u7684\u6570\u636e\uff09:\"<\/span><<<\/span>endl;<\/span>\n\tcin>><\/span>newname;<\/span>\n\tif<\/span>(<\/span>!<\/span>copy<\/span>(<\/span>existname,<\/span>newname)<\/span>)<\/span>\n\t{<\/span>\n\t\tcout<<<\/span>\"\u554a\u54e6\uff0c\u590d\u5236\u5931\u8d25\u5566\u8036!\"<\/span><<<\/span>endl;<\/span>\n\t}<\/span>\n\telse<\/span>\n\t{<\/span>\n\t\tcout<<<\/span>\"\u590d\u5236\u6210\u529f\u5566\u5440!\"<\/span><<<\/span>endl;<\/span>\n\t}<\/span>\n}<\/span>\nelse<\/span> if<\/span>(<\/span>s==<\/span>\"8\"<\/span>)<\/span>\n{<\/span>\/\/\u67e5\u627e<\/span>\n\tmenu<\/span>(<\/span>)<\/span>;<\/span>\n\tstring dir,<\/span>filename;<\/span>\n\tcout<<<\/span>\"\u8bf7\u8f93\u5165\u76ee\u5f55\u540d:\"<\/span><<<\/span>endl;<\/span>\n\tcin>><\/span>dir;<\/span>\n\tcout<<<\/span>\"\u8bf7\u8f93\u5165\u76ee\u5f55\u540d\u6216\u6587\u4ef6\u540d:\"<\/span><<<\/span>endl;<\/span>\n\tcin>><\/span>filename;<\/span>\n\tif<\/span>(<\/span>!<\/span>find<\/span>(<\/span>dir,<\/span>filename)<\/span>)<\/span>\n\t{<\/span>\n\t\tcout<<<\/span>\"\u67e5\u627e\u5931\u8d25!\"<\/span><<<\/span>endl;<\/span>\n\t}<\/span>\n}<\/span>\nelse<\/span> if<\/span>(<\/span>s==<\/span>\"9\"<\/span>)<\/span>\n{<\/span>\n\/\/\u5217\u51fa\u76ee\u5f55\u4e2d\u5168\u90e8\u6587\u4ef6\u548c\u76ee\u5f55<\/span>\n\tmenu<\/span>(<\/span>)<\/span>;<\/span>\n\tstring dirpath;<\/span>\n\tcout<<<\/span>\"\u8bf7\u8f93\u5165\u9700\u8981\u904d\u5217\u7684\u76ee\u5f55\u540d:\"<\/span><<<\/span>endl;<\/span>\n\tcin>><\/span>dirpath;<\/span>\n\tlist<\/span>(<\/span>dirpath)<\/span>;<\/span>\n\t\/\/getFileName(*dirpath);<\/span>\n\t\/\/myls();<\/span>\n}<\/span>\nelse<\/span> if<\/span>(<\/span>s==<\/span>\"10\"<\/span>)<\/span>\n{<\/span>\n\/\/\u663e\u793a\u4e0e\u8bbe\u7f6e\u65f6\u95f4\u4e0e\u65e5\u671f<\/span>\n\tmenu<\/span>(<\/span>)<\/span>;<\/span>\n\tint<\/span> choose=<\/span>0<\/span>;<\/span>\n\tcout<<<\/span>\"\u9009\u62e9\u663e\u793a\u65f6\u95f4\u8bf7\u8f93\u51651,\u9009\u62e9\u8bbe\u7f6e\u65f6\u95f4\u8bf7\u8f93\u51652\"<\/span><<<\/span>endl;<\/span>\n\tcout<<<\/span>\"-----1 \u663e\u793a,2 \u8bbe\u7f6e.\"<\/span><<<\/span>endl;<\/span>\n\tcin>><\/span>choose;<\/span>\n\tif<\/span>(<\/span>choose=<\/span>1<\/span>)<\/span>\n\t{<\/span>\n\t\t datetime<\/span>(<\/span>)<\/span>;<\/span>\n\t}<\/span>\n\tif<\/span>(<\/span>choose=<\/span>2<\/span>)<\/span>\n\t{<\/span>\n\t\tint<\/span> y,<\/span>mon,<\/span>d,<\/span>h,<\/span>m,<\/span>s;<\/span>\n\t\tcout<<<\/span>\"\u8bf7\u4f9d\u6b21\u8f93\u5165'\u5e74 \u6708 \u65e5 \u65f6 \u5206 \u79d2'\"<\/span><<<\/span>endl;<\/span>\n\t\tcin>><\/span>y>><\/span>mon>><\/span>d>><\/span>h>><\/span>m>><\/span>s;<\/span>\n\t\tTimeSet<\/span>(<\/span>y,<\/span>mon,<\/span>d,<\/span>h,<\/span>m,<\/span>s)<\/span>;<\/span>\n\t\tcout<<<\/span>\"\u8bbe\u7f6e\u6210\u529f\"<\/span><<<\/span>endl;<\/span>\n\t}<\/span>\n\telse<\/span>\n\t{<\/span>\n\t\tcout<<<\/span>\"\u53ea\u80fd\u8f93\u5165\u20181\u2019\u6216\u20182\u2019\u5566\uff01\u4e0d\u8981\u8f93\u5165\u5176\u4ed6\u7684\u54e6\"<\/span><<<\/span>endl;<\/span>\n\t}<\/span>\n}<\/span>\nelse<\/span> if<\/span>(<\/span>s==<\/span>\"11\"<\/span>)<\/span>\n{<\/span>\n\/\/\u5207\u6362\u76ee\u5f55<\/span>\n\tmenu<\/span>(<\/span>)<\/span>;<\/span>\n\tcd<\/span>(<\/span>)<\/span>;<\/span>\n\/\/cout<<"\u8bf7\u8f93\u5165\u8981\u5207\u6362\u7684\u76ee\u5f55\u540d"<<endl;<\/span>\n\/\/cin>>dir;<\/span>\n}<\/span>\n\telse<\/span>\n\t{<\/span>\n\t\tmenu<\/span>(<\/span>)<\/span>;<\/span>\n\t\tcout<<<\/span>\"\u8f93\u5165\u51fa\u9519\u5566\u5440\uff0c\u8bf7\u518d\u8f93\u5165\u4e00\u6b21\u54e6!\"<\/span><<<\/span>endl;<\/span>\n\t}<\/span>\n}<\/span>\n\treturn<\/span> 0<\/span>;<\/span>\n}<\/span>\n<\/code><\/pre><\/p>\n","protected":false},"excerpt":{"rendered":"

5.exit\u9000\u51fa\u547d\u4ee4\u89e3\u91ca\u5668\u3002\u901a\u8fc7\u8c03\u7528\u76f8\u5173\u7684\u51fd\u6570\u5e93\u6765\u5b9e\u73b0\u6a21\u62dfshell\u547d\u4ee4\u64cd\u4f5c\u3002\u83dc\u5355\uff1a\u5728\u5217\u4e3e\u83dc\u5355\u4e4b\u524d\u5148\u628a\u63a7\u5236\u53f0\u7528clear\u547d\u4ee4\u6e05\u9664\u5185\u5bb9\uff0c\u518d\u8fdb\u884c\u663e\u793a\uff0c\u4ee5\u4fdd\u8bc1\u754c\u9762\u7f8e\u89c2\uff0c\u5728\u83dc\u5355\u4e4b\u540e\u76f4\u63a5\u8c03\u7528pwd()\u51fd\u6570\u663e\u793a\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\uff0c\u65b9\u4fbf\u7528\u6237\u67e5\u770b\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u30025.exit\u9000\u51fa\u547d\u4ee4\u89e3\u91ca\u5668\u3002\u9000\u51fa\u547d\u4ee4\u89e3\u91ca\u5668\uff08\u547d\u4ee45\uff09<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[988],"tags":[548,3967,3966,3965],"class_list":["post-294067","post","type-post","status-publish","format-standard","hentry","category-tougao","tag-c","tag-hsgn","tag-twj-2","tag-czxtkcsj"],"acf":[],"_links":{"self":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/294067","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/comments?post=294067"}],"version-history":[{"count":0,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/294067\/revisions"}],"wp:attachment":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media?parent=294067"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/categories?post=294067"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/tags?post=294067"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}