{"id":811,"date":"2023-02-01T20:50:07","date_gmt":"2023-02-01T12:50:07","guid":{"rendered":"https:\/\/www.datarelab.com\/blog\/?p=811"},"modified":"2023-02-01T20:50:07","modified_gmt":"2023-02-01T12:50:07","slug":"%e4%bd%bf%e7%94%a8python%e7%94%9f%e6%88%90baidupcs%e5%b7%a5%e5%85%b7%e7%9a%84%e7%99%be%e5%ba%a6%e7%bd%91%e7%9b%98%e7%a7%92%e4%bc%a0%e4%bf%a1%e6%81%af","status":"publish","type":"post","link":"https:\/\/www.datarelab.com\/blog\/Technical_literature\/811.html","title":{"rendered":"\u4f7f\u7528Python\u751f\u6210BaiduPCS\u5de5\u5177\u7684\u767e\u5ea6\u7f51\u76d8\u79d2\u4f20\u4fe1\u606f"},"content":{"rendered":"<p>\u6709\u4e00\u6b21\u60f3\u4f7f\u7528\u767e\u5ea6\u7f51\u76d8\u81ea\u5e26\u7684Windows\u5ba2\u6237\u7aef\u4e0a\u4f20\u4e00\u4e9b\u5927\u91cf\u97f3\u4e50\u6587\u4ef6\uff0c\u8fd9\u4e9b\u97f3\u4e50\u6587\u4ef6\u5176\u4ed6\u767e\u5ea6\u7f51\u76d8\u7528\u6237\u80af\u5b9a\u65e9\u90fd\u4e0a\u4f20\u8fc7\uff0c\u6240\u4ee5\u57fa\u672c\u8fd9\u4e9b\u6587\u4ef6\u4e0d\u4f1a\u5360\u7528\u592a\u591a\u7f51\u7edc\u4e0a\u4f20\u5e26\u5bbd\uff0c\u4f46\u662f\u767e\u5ea6\u7f51\u76d8\u81ea\u5e26\u7684Windows\u5ba2\u6237\u7aef\u8ba1\u7b97\u6587\u4ef6\u7684md5\u8fc7\u7a0b\u975e\u5e38\u6162\uff0c\u4f30\u8ba1\u662f\u4e3a\u4e86\u907f\u514d\u8ba1\u7b97md5\u8fc7\u7a0b\u5f71\u54cd\u7535\u8111\u6574\u4f53\u6027\u80fd\uff0c\u6240\u4ee5\u6545\u610f\u6ca1\u6709\u5f00\u5168\u901f\u8ba1\u7b97\uff0c\u540e\u6765\u5229\u7528BaiduPCS\u547d\u4ee4\u884c\u5de5\u5177\u8fdb\u884c\u4e0a\u4f20\uff0c\u6240\u4ee5\u5199\u4e86\u4e00\u4e2aPython\u4ee3\u7801\u8fdb\u884cmd5\u8ba1\u7b97\uff0c\u8ba1\u7b97\u8fc7\u7a0b\u53ef\u4ee5\u8fbe\u5230\u78c1\u76d8\u7684\u5cf0\u503c\u901f\u5ea6\u3002<\/p>\n<pre class=\"lang:python decode:true \" ># -*- coding: utf-8 -*-\r\n\r\nimport os\r\nimport io\r\nimport hashlib\r\n\r\n\r\ndef GetFileMD5(path, iFileSize):\r\n    slicemd5 = None\r\n    md5 = None\r\n    with open(path, 'rb') as f:\r\n        slicemd5 = hashlib.md5(f.read(min(iFileSize, 262144))).hexdigest()\r\n        f.seek(0, io.SEEK_SET)\r\n        md5 = hashlib.md5(f.read()).hexdigest()\r\n    return md5, slicemd5\r\n\r\n\r\ndef traversal_files(path):\r\n    for dir in os.listdir(path):\r\n        dir = os.path.join(path, dir)\r\n        if os.path.isdir(dir):\r\n            traversal_files(dir)\r\n        else:\r\n            iFileSize = os.path.getsize(dir)\r\n            md5, slicemd5 = GetFileMD5(dir, iFileSize)\r\n            strPath = dir[2:]\r\n            strPath = strPath.replace('\\\\', '\/')\r\n            print('.\/BaiduPCS-Go rapidupload -length=%d -md5=%s -slicemd5=%s \"%s\"' %\r\n                  (iFileSize, md5, slicemd5, strPath), file=open(\".\/output.txt\", \"a\"))\r\n\r\n\r\nif __name__ == '__main__':\r\n    traversal_files(\"G:\\\\part1\")\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6709\u4e00\u6b21\u60f3\u4f7f\u7528\u767e\u5ea6\u7f51\u76d8\u81ea\u5e26\u7684Windows\u5ba2\u6237\u7aef\u4e0a\u4f20\u4e00\u4e9b\u5927\u91cf\u97f3\u4e50\u6587\u4ef6\uff0c\u8fd9\u4e9b\u97f3\u4e50\u6587\u4ef6\u5176\u4ed6\u767e\u5ea6\u7f51\u76d8\u7528\u6237\u80af\u5b9a\u65e9\u90fd\u4e0a\u4f20\u8fc7 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-811","post","type-post","status-publish","format-standard","hentry","category-Technical_literature"],"views":29,"_links":{"self":[{"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/posts\/811","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/comments?post=811"}],"version-history":[{"count":0,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/posts\/811\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/media?parent=811"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/categories?post=811"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/tags?post=811"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}