{"id":207997,"date":"2025-07-08T13:10:01","date_gmt":"2025-07-08T05:10:01","guid":{"rendered":"https:\/\/server.hk\/cnblog\/207997\/"},"modified":"2025-07-08T13:10:01","modified_gmt":"2025-07-08T05:10:01","slug":"%e7%bb%93%e6%9e%84%e5%b5%8c%e5%85%a5%ef%bc%9a%e6%97%a0%e6%b3%95%e5%bc%95%e7%94%a8%e6%9c%aa%e5%af%bc%e5%87%ba%e7%9a%84%e5%90%8d%e7%a7%b0-os-filestat","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/207997\/","title":{"rendered":"\u7ed3\u6784\u5d4c\u5165\uff1a\u65e0\u6cd5\u5f15\u7528\u672a\u5bfc\u51fa\u7684\u540d\u79f0 os.fileStat"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>\u7ed3\u6784\u5d4c\u5165\uff1a\u65e0\u6cd5\u5f15\u7528\u672a\u5bfc\u51fa\u7684\u540d\u79f0 os.fileStat<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-27 18:54:37<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u79ef\u7d2f\u77e5\u8bc6\uff0c\u80dc\u8fc7\u79ef\u84c4\u91d1\u94f6\uff01\u6bd5\u7adf\u5728Golang\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4f1a\u9047\u5230\u5404\u79cd\u5404\u6837\u7684\u95ee\u9898\uff0c\u5f80\u5f80\u90fd\u662f\u4e00\u4e9b\u7ec6\u8282\u77e5\u8bc6\u70b9\u8fd8\u6ca1\u6709\u638c\u63e1\u597d\u800c\u5bfc\u81f4\u7684\uff0c\u56e0\u6b64\u57fa\u7840\u77e5\u8bc6\u70b9\u7684\u79ef\u7d2f\u662f\u5f88\u91cd\u8981\u7684\u3002\u4e0b\u9762\u672c\u6587\u300a\u7ed3\u6784\u5d4c\u5165\uff1a\u65e0\u6cd5\u5f15\u7528\u672a\u5bfc\u51fa\u7684\u540d\u79f0 os.fileStat\u300b\uff0c\u5c31\u5e26\u5927\u5bb6\u8bb2\u89e3\u4e00\u4e0b\u77e5\u8bc6\u70b9\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u8bd5\u56fe\u4ece\u4e0d\u4e45\u524d\u7684\u7b54\u6848\u4e2d\u5d4c\u5165\u4ee5\u4e0b\u63d0\u793a\u3002 <\/p>\n<pre>\/\/ has all methods of *sql.row.\ntype myrow struct {\n    *sql.row\n}<\/pre>\n<p>\u4f46\u662f\uff0c\u5f53\u6211\u5c1d\u8bd5 https:\/\/play.golang.org\/p\/vnyx4ltwisn \u65f6\uff0c\u4f1a\u629b\u51fa\u9519\u8bef <code>cannot \u5f15\u7528\u672a\u5bfc\u51fa\u7684\u540d\u79f0 os.filestat<\/code><\/p>\n<pre>package main\n\nimport (\n    \"fmt\"\n    \"os\"\n)\n\ntype myFileStat struct {\n    info *os.fileStat\n}\n\n\nfunc main() {\n    fmt.Println(\"Hello, playground\")\n}<\/pre>\n<p>\u60a8\u80fd\u7ed9\u6211\u6307\u51fa\u6b63\u786e\u7684\u65b9\u5411\u5417\uff1f <\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u5728 go \u4e2d\uff0c\u4ee5\u5c0f\u5199\u5b57\u6bcd\u5f00\u5934\u7684\u6807\u8bc6\u7b26\u662f\u4e0d\u53ef\u89c1\u7684\u3002\u56e0\u6b64\u51fa\u73b0\u201c\u672a\u5bfc\u51fa\u540d\u79f0 os.fileStat\u201d\u9519\u8bef\u3002 \u67e5\u770b<\/p>\n<p>\u542c\u8d77\u6765\u60a8\u6b63\u5728\u5bfb\u627e\u7c7b\u4f3c os.Stat \u548c os.LStat \u4e4b\u7c7b\u7684\u4e1c\u897f\u3002\u5b83\u4eec\u8fd4\u56de\u4ece os \u5305\u5185\u90e8\u7684 fileStat \u6d3e\u751f\u7684 FileInfo \u7c7b\u578b\u3002<\/p>\n<p>\u5728\u6b64\u5904\u67e5\u770b unix os.Stat \u7684\u5b9e\u73b0 <\/p>\n<p>\u6587\u4e2d\u5173\u4e8e\u7684\u77e5\u8bc6\u4ecb\u7ecd\uff0c\u5e0c\u671b\u5bf9\u4f60\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff01\u82e5\u662f\u53d7\u76ca\u532a\u6d45\uff0c\u90a3\u5c31\u52a8\u52a8\u9f20\u6807\u6536\u85cf\u8fd9\u7bc7\u300a\u7ed3\u6784\u5d4c\u5165\uff1a\u65e0\u6cd5\u5f15\u7528\u672a\u5bfc\u51fa\u7684\u540d\u79f0 os.fileStat\u300b\u6587\u7ae0\u5427\uff0c\u4e5f\u53ef\u5173\u6ce8\u516c\u4f17\u53f7\u4e86\u89e3\u76f8\u5173\u6280\u672f\u6587\u7ae0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-207997","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207997","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=207997"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207997\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=207997"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=207997"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=207997"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}