{"id":482,"date":"2023-06-20T21:01:07","date_gmt":"2023-06-20T13:01:07","guid":{"rendered":"https:\/\/www.gzlcy.cn\/?p=482"},"modified":"2023-06-20T21:01:07","modified_gmt":"2023-06-20T13:01:07","slug":"vba%e6%93%8d%e4%bd%9c%e6%96%87%e4%bb%b6%e5%92%8c%e6%96%87%e4%bb%b6%e5%a4%b9","status":"publish","type":"post","link":"http:\/\/www.gzlcy.cn\/?p=482","title":{"rendered":"VBA\u64cd\u4f5c\u6587\u4ef6\u548c\u6587\u4ef6\u5939"},"content":{"rendered":"<p>\u83b7\u53d6\u5f53\u524d<a href='https:\/\/www.gzlcy.cn\/?p=471' title='\u6587\u4ef6' target='_blank' rel=\"noopener\">\u6587\u4ef6<\/a>\u5939\u7684\u540d\u79f0\uff08CurDir <a href='https:\/\/www.gzlcy.cn\/?p=199' title='\u51fd\u6570' target='_blank' rel=\"noopener\">\u51fd\u6570<\/a>\uff09<\/p>\n<p>\u5f53\u4f60\u4f7f\u7528\u6587\u4ef6\u65f6\uff0c\u7ecf\u5e38\u4f1a\u9700\u8981\u77e5\u9053\u5f53\u524d\u6587\u4ef6\u5939\u7684\u540d\u79f0\uff0c\u4f60\u4f7f\u7528CurDir\u51fd\u6570\u8f7b\u6613\u5730\u83b7\u53d6\u8be5\u4fe1\u606f\uff1a<\/p>\n<p><pre>CurDir([drive])<\/pre>\n<\/p>\n<p>Drive\u662f\u4e00\u53ef\u9009\u53c2\u6570\uff0c\u5982\u679c\u4f60\u5ffd\u7565\u5b83\uff0cVBA\u5c06\u4f7f\u7528\u5f53\u524d\u9a71\u52a8\uff08drive\uff09\u3002<\/p>\n<p>CurDir\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u6587\u4ef6\u8def\u5f84\u4f5c\u4e3aVariant\uff08\u53d8\u91cf\uff09\u3002\u5982\u679c\u8981\u8fd4\u56de\u4f5c\u4e3a<a href='https:\/\/www.gzlcy.cn\/?p=95' title='\u5b57\u7b26' target='_blank' rel=\"noopener\">\u5b57\u7b26<\/a>\u4e32\uff08String\uff09\u7684\u8def\u5f84\u7684\u8bdd\uff0c\u5c31\u5f97\u4f7f\u7528CurDir$\uff08\u8fd9\u91cc\u7684$\u662f\u5b57\u7b26\u4e32\u7684\u7c7b\u578b\u58f0\u660e\u5b57\u7b26\uff09\u3002\u8ba9\u6211\u4eec\u5728\u7acb\u5373<a href='https:\/\/www.gzlcy.cn\/?p=327' title='\u7a97\u53e3' target='_blank' rel=\"noopener\">\u7a97\u53e3<\/a>\u91cc\u505a\u4e9b\u7ec3\u4e60\uff0c\u7ec3\u4e60\u4f7f\u7528\u8fd9\u4e9b\u51fd\u6570\u5427\uff1a<\/p>\n<p>1. \u6253\u5f00\u4e00\u4e2a\u65b0\u5de5\u4f5c\u7c3f\uff0c\u5e76\u4e14\u5207\u6362\u5230VB\u7f16\u8f91\u5668\u7a97\u53e3<\/p>\n<p>2. \u6fc0\u6d3b\u7acb\u5373\u7a97\u53e3\u5e76\u6572\u5165\u4e0b\u8ff0\u4ee3\u7801\uff1a<\/p>\n<p><pre>?CurDir<\/pre>\n<\/p>\n<p>\u5f53\u4f60\u6309\u4e0b\u56de\u8f66\uff0cVB\u5c31\u663e\u793a\u5f53\u524d\u6587\u4ef6\u5939\u540d\u79f0\uff0c\u4f8b\u5982\uff1a<\/p>\n<p>C:<\/p>\n<p>\u5982\u679c\u4f60\u6709\u7b2c\u4e8c\u4e2a\u786c\u76d8\uff08\u6216\u8005\u5149\u9a71\uff09\u7684\u8bdd\uff0c\u4f60\u53ef\u4ee5\u83b7\u53d6D\u76d8\u4e0a\u7684\u5f53\u524d\u6587\u4ef6\u5939\uff0c\u4f8b\u5982\uff1a<\/p>\n<p><pre>?CurDir(\u201cD:\u201d)<\/pre>\n<\/p>\n<p>\u5982\u679c\u4f60\u63d0\u4f9b\u4e86\u4e00\u4e2a\u5e76\u4e0d\u5b58\u5728\u7684\u9a71\u52a8\u5b57\u6bcd\u7684\u8bdd\uff0cVB\u5c31\u5c06\u663e\u793a\u4e0b\u8ff0\u9519\u8bef\u4fe1\u606f\uff1a\u201c\u8bbe\u5907\u4e0d\u53ef\u7528\u201d<\/p>\n<p>3. \u8981\u50a8\u5b58\u5f53\u524d\u52a8\u540d\u79f0\u5230\u53d8\u91cfmyDrive\uff0c\u53ef\u4ee5\u8f93\u5165\u4e0b\u8ff0\u6307\u4ee4\uff1a<\/p>\n<p><pre>myDrive = Left(CurDir$,1)<\/pre>\n<\/p>\n<p>\u5f53\u4f60\u6309\u4e0b\u56de\u8f66\u952e\u65f6\uff0cVB\u5c06\u5f53\u524d\u9a71\u52a8\u5668\u7684\u5b57\u6bcd\u50a8\u5b58\u5230\u53d8\u91cfmyDrive<\/p>\n<p>\u6572\u5165\u4e0b\u8ff0\u6307\u4ee4\u5e76\u56de\u8f66\uff0c\u53ef\u4ee5\u68c0\u67e5\u53d8\u91cfmyDrive\u7684\u5185\u5bb9\uff1a<\/p>\n<p><pre>?myDrive<\/pre>\n<\/p>\n<p>\u4f60\u8fd8\u53ef\u4ee5\u5c06\u4e0a\u9762\u7684\u6307\u4ee4\u6539\u4e3a\u5982\u4e0b\uff1a<\/p>\n<p><pre>myDrive = left(CurDir$,1) &amp; \":\"<\/pre>\n<\/p>\n<p>VB\u5c06\u8fd4\u56de\u9a71\u52a8\u5668\u5b57\u6bcd\uff0c\u540e\u9762\u5e26\u6709\u4e00\u4e2a\u5192\u53f7\u3002<\/p>\n<p>\u66f4\u6539\u6587\u4ef6\u6216\u6587\u4ef6\u5939\u540d\u79f0\uff08Name \u51fd\u6570\uff09<\/p>\n<p>\u4f7f\u7528\u51fd\u6570Name\u53ef\u4ee5\u91cd\u547d\u540d\u6587\u4ef6\u6216\u8005\u6587\u4ef6\u5939\uff0c\u4f8b\u5982\uff1a<\/p>\n<p><pre>Name old_pathname As new_pathname<\/pre>\n<\/p>\n<p>Old_pathname\u662f\u4f60\u60f3\u7528\u91cd\u547d\u540d\u7684\u6587\u4ef6\u6216\u6587\u4ef6\u5939\u7684\u540d\u79f0\u548c\u8def\u5f84\uff0cNew_pathname\u5219\u660e\u786e\u6587\u4ef6\u6216\u6587\u4ef6\u5939\u7684\u65b0\u540d\u79f0\u548c\u4f4d\u7f6e\u3002\u4f7f\u7528\u51fd\u6570Name\uff0c\u4f60\u53ef\u4ee5\u5c06\u4e00\u4e2a\u6587\u4ef6\u4ece\u4e00\u4e2a\u6587\u4ef6\u5939\u79fb\u52a8\u5230\u53e6\u5916\u4e00\u4e2a\u6587\u4ef6\u5939\uff0c\u4f46\u662f\uff0c\u4f60\u4e0d\u53ef\u4ee5\u79fb\u52a8\u6587\u4ef6\u5939\u3002<\/p>\n<p>\u8bf7\u5728\u7acb\u5373\u7a97\u53e3\u91cc\u8bd5\u6f14\u8be5\u51fd\u6570\uff08\u7528\u4f60\u6587\u4ef6\u7684\u5b9e\u9645\u540d\u79f0\u66ff\u6362\u793a\u4f8b\u540d\u79f0\uff09\u3002\u8fd9\u91cc\u6709\u4e9b\u9700\u8981\u8003\u8651\u7684\u6ce8\u610f\u4e8b\u9879\uff1a<\/p>\n<p>\u2460\u5728New_pathname\u91cc\u7684\u6587\u4ef6\u540d\u79f0\u4e0d\u8981\u6307\u5411\u5df2\u7ecf\u5b58\u5728\u7684\u6587\u4ef6<\/p>\n<p>Name &#8220;C:System.1st &#8221; As &#8220;C:test.txt&#8221;<\/p>\n<p>\u56e0\u4e3a\u6587\u4ef6C:test.txt\u5df2\u7ecf\u5b58\u5728\u4e8eC\u76d8\uff0cVB\u5c06\u663e\u793a\u9519\u8bef\u4fe1\u606f\uff1a\u201c\u6587\u4ef6\u5df2\u5b58\u5728\u201d\uff0c\u540c\u6837\uff0c\u5982\u679c\u4f60\u8981\u91cd\u547d\u540d\u7684\u6587\u4ef6\u4e0d\u5b58\u5728\u7684\u8bdd\uff0c\u5c31\u4f1a\u51fa\u73b0\u201c\u6587\u4ef6\u672a\u627e\u5230\u201d\u7684\u9519\u8bef\u4fe1\u606f\u3002<\/p>\n<p>\u2461\u5982\u679cNew_pathname\u5df2\u7ecf\u5b58\u5728\uff0c\u5e76\u4e14\u548cOld_pathname\u4e0d\u540c\uff0c\u51fd\u6570Name\u5fc5\u8981\u65f6\u5c06\u6587\u4ef6\u79fb\u52a8\u5230\u65b0\u6587\u4ef6\u5939\u5e76\u4e14\u66f4\u6539\u5b83\u7684\u540d\u79f0\u3002<\/p>\n<p>Name &#8220;C:System.1st &#8221; As &#8220;D:test.txt&#8221;<\/p>\n<p>\u56e0\u4e3a\u6587\u4ef6test.txt\u5728D\u76d8\u7684\u6839\u76ee\u5f55\u4e0b\u5e76\u4e0d\u5b58\u5728\uff0cVB\u5c06C:System.1st<\/p>\n<p>\u79fb\u52a8\u5230\u6307\u5b9a\u7684\u9a71\u52a8\u76d8\uff0c\u7136\u800c\uff0c\u5e76\u4e0d\u91cd\u547d\u540d\u8be5\u6587\u4ef6\u3002\uff08\u672c\u6bb5\u4e0e\u4e0a\u9762\u7684\u5185\u5bb9\u4f3c\u4e4e\u77db\u76fe\uff0c\u800c\u4e14\u672a\u80fd\u8bd5\u9a8c\u6210\u529f\uff0c\u672a\u77e5\u662f\u539f\u4e66\u5931\u8bef\u4e0e\u5426\u3002\u8bfb\u8005\u5e94\u4ed4\u7ec6\u9a8c\u8bc1\uff09<\/p>\n<p>\u2462\u5982\u679cNew_pathname\u548cOld_pathname\u6307\u5411\u4e0d\u540c\u7684\u76ee\u5f55\uff0c\u4ee5\u53ca\u63d0\u4f9b\u7684\u6587\u4ef6\u540d\u79f0\u76f8\u540c\uff0c\u90a3\u4e48Name\u51fd\u6570\u5c06\u6307\u5b9a\u7684\u6587\u4ef6\u79fb\u5230\u65b0\u5730\u5740\uff0c\u4e0d\u7528\u66f4\u6539\u6587\u4ef6\u540d\u3002<\/p>\n<p>Name &#8220;D:test.txt &#8221; As &#8220;C:DOStest.txt&#8221;<\/p>\n<p>\u4e0a\u9762\u7684\u6307\u4ee4\u5c06test.txt\u79fb\u52a8\u5230C\u76d8\u4e0b\u7684DOS\u6587\u4ef6\u5939\u91cc\u3002<\/p>\n<p>\u6280\u5de7\uff1a\u4f60\u4e0d\u80fd\u91cd\u547d\u540d\u5f00\u542f\u7684\u6587\u4ef6<\/p>\n<p>\u5728\u91cd\u547d\u540d\u6587\u4ef6\u4e4b\u524d\uff0c\u4f60\u5fc5\u987b\u5173\u95ed\u8be5\u6587\u4ef6\u3002\u6587\u4ef6\u540d\u79f0\u91cc\u4e0d\u80fd\u5305\u542b\u901a\u914d\u7b26\u201c*\u201d\u6216\u8005\u201c?\u201d\u3002<\/p>\n<p>\u68c0\u67e5\u6587\u4ef6\u6216\u6587\u4ef6\u5939\u662f\u5426\u5b58\u5728\uff08Dir \u51fd\u6570\uff09<\/p>\n<p>Dir\u51fd\u6570\uff0c\u8fd4\u56de\u6587\u4ef6\u6216\u8005\u6587\u4ef6\u5939\u540d\u79f0\uff0c\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<p><pre>Dir[(pathname[, attributes])]<\/pre>\n<\/p>\n<p>Dir\u51fd\u6570\u7684\u4e24\u4e2a\u53c2\u6570\u90fd\u662f\u53ef\u9009\u7684\uff0cpathname\u662f\u6587\u4ef6\u6216\u6587\u4ef6\u5939\u540d\u79f0\uff0c\u5bf9\u4e8e\u53c2\u6570attributes\uff0c\u4f60\u53ef\u4ee5\u4e0b\u5217\u5e38\u91cf\u6216\u8005\u6570\u503c\u4e4b\u4e00\uff1a<\/p>\n<p><img src='https:\/\/p3-sign.toutiaoimg.com\/pgc-image\/7cd91bc1e1514ae59edafdd097855ea0~noop.image?_iz=58558&amp;from=article.pc_detail&amp;x-expires=1687870864&amp;x-signature=TO2x6stdOJdFE8JZQEgbR9zzciQ%3D' alt='\u65e5\u672c\u597314\u5c81\u80f8\u4e0b\u5939\u7b14_\u5939\u91ce\u5154\u4e0b\u5939\u7684\u4f4d\u7f6e\u548b\u9009_\u4e0d\u540c\u6587\u4ef6\u5939\u4e0b\u79fb\u52a8\u65b9\u6cd5' \/><\/p>\n<p>Dir\u51fd\u6570\u5e38\u7528\u6765\u68c0\u67e5\u67d0\u4e2a\u6587\u4ef6\u6216\u6587\u4ef6\u5939\u662f\u5426\u5b58\u5728\uff0c\u5982\u679c\u4e0d\u5b58\u5728\uff0c\u90a3\u4e48\u5c31\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\uff08\u201d\u201d\uff09\u3002\u6211\u4eec\u5230\u7acb\u5373\u7a97\u53e3\u91cc\u8bd5\u9a8c\u51e0\u4e2aDir\u51fd\u6570\u7684\u7ec3\u4e60\uff1a<\/p>\n<p>1. \u5728\u7acb\u5373\u7a97\u53e3\uff0c\u8f93\u5165\u4e0b\u8ff0\u6307\u4ee4\uff1a<\/p>\n<p><pre>?Dir(\"C:\", vbNormal)<\/pre>\n<\/p>\n<p>\u4f60\u4e00\u65e6\u6309\u4e0b\u56de\u8f66\u952e\uff0cVB\u5c31\u4f1a\u8fd4\u56de\u8be5\u6587\u4ef6\u5939\u4e0b\u7684\u7b2c\u4e00\u4e2a\u6587\u4ef6\u540d\u3002\u666e\u901a\u6587\u4ef6\uff08vbNormal\uff09\u5c31\u662f\u9664\u9690\u85cf\uff0c\u5377\u6807\uff0c\u76ee\u5f55\uff0c\u6587\u4ef6\u5939\u6216\u7cfb\u7edf\u6587\u4ef6\u4e4b\u5916\u7684\u4efb\u4f55\u6587\u4ef6\u3002<\/p>\n<p>\u8981\u8fd4\u56de\u5f53\u524d\u76ee\u5f55\u4e0b\u7684\u5176\u5b83\u6587\u4ef6\u540d\u79f0\u7684\u8bdd\uff0c\u5c31\u4f7f\u7528\u4e0d\u5e26\u53c2\u6570\u7684Dir\u51fd\u6570\uff1a<\/p>\n<p>?Dir \uff08\u5e76\u4e14\u56de\u8f66\uff09<\/p>\n<p>2. \u5728\u7acb\u5373\u7a97\u53e3\u91cc\u8f93\u5165\u4e0b\u5217\u6307\u4ee4\uff0c\u5e76\u4e14\u5728\u4f60\u56de\u8f66\u65f6\u68c0\u67e5\u5176\u7ed3\u679c\uff1a<\/p>\n<p><pre>mfile = Dir(\"C:\", vbHidden)\n?mfile\nmfile = Dir\n?mfile\nmfile = Dir\n?mfile\n<\/pre>\n<\/p>\n<p>3. \u5728\u7acb\u5373\u7a97\u53e3\u8f93\u5165\u4e0b\u8ff0\u6307\u4ee4\uff1a<\/p>\n<p><pre>If Dir(\"C:stamp.bat\") = \"\" Then Debug.Print \"\u6587\u4ef6\u672a\u627e\u5230\u3002\"<\/pre>\n<\/p>\n<p>\u56e0\u4e3astamp.bat\u6587\u4ef6\u4e0d\u5728C\u76d8\u4e0a\uff0c\u6240\u4ee5VB\u5c31\u5728\u7acb\u5373\u7a97\u53e3\u91cc\u5199\u4e0b\u6587\u672c\u4fe1\u606f\u201c\u6587\u4ef6\u672a\u627e\u5230\u3002\u201d<\/p>\n<p>4. \u5728\u7acb\u5373\u7a97\u53e3\u8f93\u5165\u4e0b\u8ff0\u8bed\u53e5\uff0c\u53ef\u4ee5\u68c0\u67e5\u67d0\u6587\u4ef6\u662f\u5426\u5b58\u5728\u4e8e\u67d0\u9a71\u52a8\u76d8\u4e0a\uff1a<\/p>\n<p><pre>If Dir (\"C:Autoexec.bat\") \"\" Then Debug.Print \"\u8be5\u6587\u4ef6\u4e0d\u5728C\u76d8\u4e0a\u3002\"<\/pre>\n<\/p>\n<p>\u51fd\u6570Dir\u5141\u8bb8\u4f60\u5728\u6587\u4ef6\u8def\u5f84\u540d\u4e2d\u4f7f\u7528\u901a\u914d\u7b26\u2014\u2014\u661f\u53f7\uff08*\uff09\u4ee3\u8868\u591a\u4e2a\u5b57\u7b26\uff0c\u95ee\u53f7\uff08?\uff09\u4ee3\u8868\u5355\u4e2a\u5b57\u7b26\uff1a<\/p>\n<p>\u4f8b\u5982\uff0c\u8981\u5728WINDOWS\u6587\u4ef6\u5939\u4e2d\u67e5\u627e\u6240\u6709\u914d\u7f6e\u8bbe\u7f6e\u7684\u6587\u4ef6\uff0c\u4f60\u53ef\u4ee5\u67e5\u627e\u6240\u6709\u7684INI\u6587\u4ef6\uff0c\u5982\u4e0b\uff1a<\/p>\n<p><pre>?Dir(\"C:WINNT*.ini\", vbNormal)\nsystem.ini\n?dir WIN.INI\n?dir\nWINFILE.INI\n?dir control.ini\n?dir EQUIP32.INI\n?dir\nsxpwin32.ini<\/pre>\n<\/p>\n<p>\u4e0b\u9762\u663e\u793a\u7684\u8fc7\u7a0b\u5728\u7acb\u5373\u7a97\u53e3\u91cc\u5199\u4e0a\u4e86\u786e\u5b9a\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6\u540d\u79f0\u3002\u51fd\u6570LCase$\u8ba9\u6587\u4ef6\u540d\u79f0\u663e\u793a\u4e3a\u5c0f\u5199\u5b57\u6bcd\u3002<\/p>\n<p>1. \u6253\u5f00\u4e00\u65b0\u5de5\u4f5c\u7c3f\uff0c\u5e76\u4fdd\u5b58\u4e3aChap08.xls<\/p>\n<p>2. \u5207\u6362\u5230VB\u7f16\u8f91\u5668\u7a97\u53e3\u5e76\u91cd\u547d\u540dVBA\u5de5\u7a0b\u4e3aFileMan<\/p>\n<p>3. \u63d2\u5165\u65b0\u6a21\u5757\uff0c\u91cd\u547d\u540d\u4e3aDirFunction<\/p>\n<p>4. \u8f93\u5165\u4e0b\u8ff0VBA\u8fc7\u7a0b\uff1a<\/p>\n<p><pre>Sub MyFiles()\nDim mfile As String\nDim mpath As String\nmpath = InputBox(\"Enter pathname,e.g., C:Excel\")\nIf Right(mpath, 1)  \"\" Then mpath = mpath &amp; \"\"\nmfile = Dir(mpath &amp; \"*.*\")\nIf mfile  \"\" Then Debug.Print \"Files in the \" &amp; mpath _\n&amp; \"folder\"\nDebug.Print LCase$(mfile)\nIf mfile = \"\" Then\nMsgBox \"No files found.\"\nExit Sub\nEnd If\nDo While mfile  \"\"\nmfile = Dir\nDebug.Print LCase$(mfile)\nLoop\nEnd Sub<\/pre>\n<\/p>\n<p>\u4e0a\u9762\u7684\u8fc7\u7a0bmyFiles\u5411\u7528\u6237\u8be2\u95ee\u6587\u4ef6\u8def\u5f84\u540d\u3002\u5982\u679c\u8be5\u8def\u5f84\u7ed3\u5c3e\u6ca1\u6709\u53cd\u659c\u6760\uff0c\u51fd\u6570Right\u5c31\u4f1a\u5c06\u53cd\u659c\u6760\u9644\u52a0\u5728\u8def\u5f84\u540d\u5b57\u7b26\u4e32\u4e0a\u3002\u63a5\u4e0b\u6765\uff0cVB\u5728\u8be5\u786e\u5b9a\u7684\u6587\u4ef6\u5939\u91cc\u641c\u7d22\u6240\u6709\u6587\u4ef6\uff08*\uff09\u3002\u5982\u679c\u6ca1\u6709\u6587\u4ef6\u7684\u8bdd\uff0c\u5c31\u4f1a\u6709\u4fe1\u606f\u663e\u793a\uff0c\u5982\u679c\u6587\u4ef6\u5b58\u5728\uff0c\u90a3\u4e48\u6587\u4ef6\u540d\u5c31\u4f1a\u88ab\u5199\u5165\u7acb\u5373\u7a97\u53e3\u3002<\/p>\n<p>5. \u5728\u540c\u4e00\u4e2a\u6a21\u5757\u91cc\u8f93\u5165\u53e6\u5916\u4e00\u4e2a\u8fc7\u7a0b\uff1a<\/p>\n<p><pre>Sub GetFiles()\nDim nfile As String\nDim nextRow As Integer\nnextRow = 1\n&#039;next row index\nWith Worksheets(\"Sheet1\").Range(\"A1\")\nnfile = Dir(\"C:\", vbNormal)\n.Value = nfile\nDo While nfile  \"\"\nnfile = Dir\n.Offset(nextRow, 0).Value = nfile\nnextRow = nextRow + 1\nLoop\nEnd With\nEnd Sub<\/pre>\n<\/p>\n<p>\u8fc7\u7a0bGetFiles\u83b7\u53d6C\u76d8\u6839\u76ee\u5f55\u4e0b\u7684\u6240\u6709\u6587\u4ef6\u540d\u5e76\u4e14\u5c06\u6bcf\u4e2a\u6587\u4ef6\u540d\u5199\u5165\u5de5\u4f5c\u8868\u3002<\/p>\n<p>4.\u83b7\u5f97\u6587\u4ef6\u4fee\u6539\u7684\u65e5\u671f\u548c\u65f6\u95f4\uff08FileDateTime \u51fd\u6570\uff09<\/p>\n<p>\u5982\u679c\u4f60\u7684\u8fc7\u7a0b\u9700\u8981\u77e5\u9053\u67d0\u6587\u4ef6\u7684\u6700\u540e\u4fee\u6539\u7684\u65f6\u95f4\u7684\u8bdd\uff0c\u53ef\u4ee5\u4f7f\u7528\u51fd\u6570FileDateTime\uff1a<\/p>\n<p>FileDateTime(\u6587\u4ef6\u8def\u5f84\u540d)<\/p>\n<p>\u6587\u4ef6\u8def\u5f84\u540d\u662f\u4e2a\u5b57\u7b26\u4e32\uff0c\u660e\u786e\u4f60\u8981\u7528\u7684\u6587\u4ef6\uff0c\u5e76\u4e14\u9700\u8981\u5305\u62ec\u9a71\u52a8\u548c\u6587\u4ef6\u5939\u7684\u540d\u79f0\u3002\u8be5\u51fd\u6570\u8fd4\u56de\u67d0\u6587\u4ef6\u7684\u65e5\u671f\u548c\u65f6\u95f4\u5370\u8bb0\u3002\u65e5\u671f\u548c\u65f6\u95f4\u7684\u683c\u5f0f\u53d6\u51b3\u4e8e\u89c6\u7a97\u63a7\u5236\u9762\u677f\u7684\u539f\u59cb\u8bbe\u7f6e\u3002<\/p>\n<p>\u6211\u4eec\u5728\u7acb\u5373\u7a97\u53e3\u91cc\u6765\u7ec3\u4e60\u4f7f\u7528\u8be5\u51fd\u6570\uff1a<\/p>\n<p>1. \u5728\u7acb\u5373\u7a97\u53e3\u91cc\u8f93\u5165\uff1a<\/p>\n<p><pre>?FileDateTime(\"C:config.sys\")<\/pre>\n<\/p>\n<p>\u56de\u8f66\u540e\uff0cVB\u8fd4\u56de\u4e0b\u8ff0\u683c\u5f0f\u7684\u65e5\u671f\u548c\u65f6\u95f4 5\/4\/2001 10:52:00 AM<\/p>\n<p>\u8981\u5206\u5f00\u83b7\u53d6\u65e5\u671f\u548c\u65f6\u95f4\u65f6\uff0c\u53ef\u4ee5\u5c06\u51fd\u6570FileDateTime\u4f5c\u4e3a\u51fd\u6570DateValue\u6216TimeValue\u7684\u53c2\u6570\u6765\u4f7f\u7528\u3002\u4f8b\u5982\uff1a<\/p>\n<p><pre>?DateValue(FileDateTime(\"C:config.sys\"))\n?TimeValue(FileDateTime(\"C:config.sys\"))<\/pre>\n<\/p>\n<p>2. \u5728\u7acb\u5373\u7a97\u53e3\u91cc\u5c06\u4e0b\u8ff0\u8bed\u53e5\u5728\u4e00\u884c\u8f93\u5165\uff1a<\/p>\n<p><pre>If DateValue(FileDateTime(\"C:config.sys\"))&lt; Date then Debug.Print &quot;This file was not\nmodified today.\u201d<\/pre>\n<\/p>\n<p>Date\u51fd\u6570\u8fd4\u56de\u5f53\u524d\u7cfb\u7edf\u65e5\u671f\uff0c\u4e5f\u662f\u89c6\u7a97\u63a7\u5236\u9762\u677f\u7684\u65e5\u671f<\/p>\n<p>\u5bf9\u8bdd\u6846\u91cc\u8bbe\u5b9a\u7684\u3002<\/p>\n<p>\u83b7\u5f97\u6587\u4ef6\u5927\u5c0f\uff08FileLen \u51fd\u6570\uff09<\/p>\n<p>\u5982\u679c\u4f60\u9700\u8981\u68c0\u67e5\u67d0\u6587\u4ef6\u662f\u5426\u80fd\u591f\u5b58\u5728\u67d0\u78c1\u76d8\u4e0a\uff0c\u90a3\u4e48\u4f60\u5e94\u8be5\u6309\u7167\u4e0b\u8ff0\u65b9\u5f0f\u4f7f\u7528FileLen\u51fd\u6570\uff1a<\/p>\n<p>FileLen(\u6587\u4ef6\u8def\u5f84\u540d)<\/p>\n<p>FileLen\u51fd\u6570\u4e00\u5b57\u8282\u65b9\u5f0f\u8fd4\u56de\u6587\u4ef6\u7684\u5927\u5c0f\u3002\u5982\u679c\u8be5\u6587\u4ef6\u5df2\u6253\u5f00\uff0c\u90a3\u4e48VB\u5c06\u8fd4\u56de\u8be5\u6587\u4ef6\u6700\u540e\u4e00\u4e2a\u4fdd\u5b58\u65f6\u7684\u5927\u5c0f\u3002<\/p>\n<p>\u5047\u8bbe\u4f60\u60f3\u8981\u83b7\u53d6Windows\u76ee\u5f55\u4e0b\u8fdb\u884c\u914d\u7f6e\u8bbe\u7f6e\u7684\u6240\u6709\u6587\u4ef6\u7684\u603b\u5927\u5c0f\uff1a<\/p>\n<p>1. \u5728\u5f53\u524d\u5de5\u7a0b\u91cc\u63d2\u5165\u65b0\u6a21\u5757\uff0c\u5e76\u91cd\u547d\u540d\u4e3aFileLenFunction<\/p>\n<p>2. \u5728\u4ee3\u7801\u7a97\u53e3\u4e86\u8f93\u5165\u8fc7\u7a0bTotalBytesIni\uff1a<\/p>\n<p><pre>Sub TotalBytesIni()\nDim iniFile As String\nDim allBytes As Long\niniFile = Dir(\"C:WINDOWS*.ini\")\nallBytes = 0\nDo While iniFile  \"\"\nallBytes = allBytes + FileLen(\"C:WINDOWS\" &amp; iniFile)\niniFile = Dir\nLoop\nDebug.Print \"Total bytes: \" &amp; allBytes\nEnd Sub\n<\/pre><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u83b7\u53d6\u5f53\u524d\u6587\u4ef6\u5939\u7684\u540d\u79f0\uff08CurDir \u51fd\u6570\uff09\u5f53\u4f60\u4f7f\u7528\u6587\u4ef6\u65f6\uff0c\u7ecf\u5e38\u4f1a\u9700\u8981\u77e5\u9053\u5f53\u524d\u6587\u4ef6\u5939\u7684\u540d\u79f0\uff0c\u4f60\u4f7f\u7528CurDir\u51fd\u6570\u8f7b\u6613\u5730\u83b7\u53d6\u8be5\u4fe1\u606f\uff1aCurDir(<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[254,942,34,180,645],"_links":{"self":[{"href":"http:\/\/www.gzlcy.cn\/index.php?rest_route=\/wp\/v2\/posts\/482"}],"collection":[{"href":"http:\/\/www.gzlcy.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gzlcy.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gzlcy.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gzlcy.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=482"}],"version-history":[{"count":0,"href":"http:\/\/www.gzlcy.cn\/index.php?rest_route=\/wp\/v2\/posts\/482\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.gzlcy.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=482"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gzlcy.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=482"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gzlcy.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=482"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}