{"id":4772,"date":"2022-07-27T20:58:34","date_gmt":"2022-07-27T12:58:34","guid":{"rendered":"https:\/\/seit2019.xyz\/?p=4772"},"modified":"2022-08-02T20:39:40","modified_gmt":"2022-08-02T12:39:40","slug":"6-1-%e5%89%a7%e9%9b%86%e6%89%b9%e9%87%8f%e9%87%8d%e5%91%bd%e5%90%8d","status":"publish","type":"post","link":"https:\/\/seit2019.xyz\/?p=4772","title":{"rendered":"6.1 \u5267\u96c6\u6279\u91cf\u91cd\u547d\u540d"},"content":{"rendered":"<h1>6.1 \u5267\u96c6\u6279\u91cf\u91cd\u547d\u540d<\/h1>\n<h3>6.1.1 \u573a\u666f<\/h3>\n<p>\u901a\u5e38\uff0c\u5728\u7ebf\u4e0b\u8f7d\u7684\u5267\u96c6\u6765\u6e90\u4e0d\u540c\uff0c\u6587\u4ef6\u547d\u540d\u4e94\u82b1\u516b\u95e8\uff0c\u9700\u8981\u91cd\u65b0\u547d\u540d\uff0c\u6574\u7406\u5230\u76f8\u5e94\u7ed9\u6587\u4ef6\u5939\u4e2d\u3002\u5f53\u5267\u96c6\u6bd4\u8f83\u591a\u65f6\uff0c \u624b\u5de5\u547d\u540d\u6bd4\u8f83\u9ebb\u70e6\uff0c\u5e38\u89c4\u7684\u89e3\u51b3\u65b9\u5f0f\u662f\uff1a\u5b89\u88c5\u6279\u91cf\u547d\u540d\u8f6f\u4ef6\uff0c\u5b9e\u73b0\u6279\u91cf\u547d\u540d\u3002\u7136\u800c\uff0c\u7f51\u4e0a\u5f88\u591a\u6279\u91cf\u547d\u540d\u8f6f\u4ef6\u6765\u6e90\u590d\u6742\uff0c\u529f\u80fd\u53c2\u5dee\u4e0d\u9f50\uff0c\u5b89\u88c5\u540e\u5f80\u5f80\u9700\u8981\u6ce8\u518c\u6fc0\u6d3b\uff0c\u95ee\u9898\u5f88\u591a\u3002\u56e0\u6b64\uff0c\u5f88\u6709\u5fc5\u8981\u901a\u8fc7Python\u4ee3\u7801\u5b9e\u73b0\u8fd9\u4e9b\u529f\u80fd\uff0c\u907f\u514d\u8fd9\u4e9b\u95ee\u9898\u3002<\/p>\n<hr \/>\n<h3>6.1.2 \u529f\u80fd\u9700\u6c42<\/h3>\n<p>Python\u7f16\u7a0b\u9700\u8981\u5b9e\u73b02\u4e2a\u529f\u80fd\uff1a<\/p>\n<ul>\n<li>\n<p>\u5267\u96c6\u7684\u6279\u91cf\u91cd\u547d\u540d<\/p>\n<\/li>\n<li>\n<p>\u5267\u96c6\u5b58\u653e\u5230\u6307\u5b9a\u7684\u6587\u4ef6\u5939\u5185\uff08\u6587\u4ef6\u5939\u547d\u540d\uff1a\u5267\u96c6\u540d\/\u5b63\uff09<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h3>6.1.3 \u539f\u7406<\/h3>\n<p><strong>\u7a0b\u5e8f\u5305<\/strong>\uff1a<\/p>\n<ul>\n<li>\n<p>os \u662fPython\u5185\u7f6e\u7684\u7a0b\u5e8f\u5305\uff0c\u4e3b\u8981\u529f\u80fd\u662f\u6587\u4ef6\u548c\u6587\u4ef6\u5939\u7684\u521b\u5efa\u3001\u547d\u540d\u7b49\u64cd\u4f5c\u3002<\/p>\n<\/li>\n<li>\n<p>shutil \u662fPython\u5185\u7f6e\u7a0b\u5e8f\u5305\uff0c\u4e3b\u8981\u529f\u80fd\u662f\u6587\u4ef6\u7684\u79fb\u52a8\u7b49\u64cd\u4f5c\u3002<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u5b9e\u73b0\u6d41\u7a0b<\/strong>\uff1a<\/p>\n<ul>\n<li>\n<p>\u8bbe\u5b9a\u6587\u4ef6\u6279\u91cf\u547d\u540d\u7684<strong>\u66ff\u6362\u53c2\u6570<\/strong>(\u6bcf\u6b21\u547d\u540d\u524d\u4fee\u6539)<\/p>\n<\/li>\n<li>\n<p>\u5b9a\u4e49\u91cd\u547d\u540drename()\u51fd\u6570\uff0c\u5b9e\u73b0\u529f\u80fd\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\n<p>\u6839\u636e\u5267\u96c6\u540d\/\u5b63\uff0c\u751f\u6210\u6307\u5b9a\u7684\u6587\u4ef6\u5939<\/p>\n<\/li>\n<li>\n<p>os.listdir()\u83b7\u53d6\u6587\u4ef6\u5939\u5185\u6240\u6709\u6587\u4ef6\u540d\uff0c\u751f\u6210\u5217\u8868<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528for\u5faa\u73af\u548cos.rename()\uff0c\u6279\u91cf\u66ff\u6362\u539f\u6587\u4ef6\u540d\u4e2d\u65e0\u5173\u90e8\u5206\uff0c\u5b9e\u73b0\u91cd\u547d\u540d<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528shutil.move()\uff0c\u5c06\u547d\u540d\u540e\u7684\u6587\u4ef6\u6279\u91cf\u79fb\u52a8\u5230\u6307\u5b9a\u7684\u6587\u4ef6\u5939\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u8c03\u7528\u91cd\u547d\u540d\u51fd\u6570rename()\uff0c\u5b8c\u6210\u6279\u91cf\u547d\u540d\u548c\u6587\u4ef6\u79fb\u52a8\u3002<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h3>6.1.4 \u4ee3\u7801<\/h3>\n<pre><code class=\"language-python\"># \u5267\u96c6\u6279\u91cf\u91cd\u547d\u540d\n\n# \u5bfc\u5165\u7a0b\u5e8f\u5305\nimport os\nimport shutil\n\n# \u53c2\u6570\u4fee\u6539\u533a\n# \u5047\u5b9a\u5267\u96c6\u540d\u4e3a\uff1aBBC.Africa.2013.EP01.BluRay.1080p.3Audio.DTS-HD.MA.5.1.x265.10bit-ALT\nname = &quot;\u975e\u6d32&quot;            # \u8bbe\u5b9a\u5267\u96c6\u540d\nseason = &quot;S01&quot;            # \u8bbe\u5b9a\u5b63\nfilename_head = &quot;BBC.Africa.2013.EP&quot;   # \u8bbe\u5b9a\u5267\u96c6\u540d\u524d\u534a\u90e8\nfilename_tail = &quot;.BluRay.1080p.3Audio.DTS-HD.MA.5.1.x265.10bit-ALT&quot;   # \u8bbe\u5b9a\u5267\u96c6\u540d\u540e\u534a\u90e8\npath_raw =  r&quot;W:\\0.Download\\0.TV\\\u5f85\u5904\u7406&quot;         # \u8bbe\u5b9a\u5f85\u547d\u540d\u5267\u96c6\u7684\u8def\u5f84\npath_dest = r&quot;W:\\0.Download\\0.TV&quot;               # \u8bbe\u5b9a\u5267\u96c6\u6700\u7ec8\u5b58\u653e\u8def\u5f84\n\n# \u5b9a\u4e49\u547d\u540d\u51fd\u6570\ndef rename(name, season, filename_head, filename_tail):\n    path1 = path_dest + &quot;\\\\&quot; + name   # \u8bbe\u5b9a\u5df2\u547d\u540d\u5267\u96c6\u8def\u5f84\n    path2 = path1 + &quot;\\\\&quot; + season            # \u8bbe\u5b9a\u5df2\u547d\u540d\u5267\u96c6\u7684\u5b63\u8def\u5f84\n    os.mkdir(path1)                     # \u751f\u6210\u5df2\u547d\u540d\u5267\u96c6\u6587\u4ef6\u5939\n    os.mkdir(path2)                     # \u751f\u6210\u5df2\u547d\u540d\u5267\u96c6\u7684\u5b63\u6587\u4ef6\u5939\n    os.chdir(path_raw)                      # \u9009\u62e9\u5f85\u547d\u540d\u5267\u96c6\u8def\u5f84\n    file_list0 = os.listdir(path_raw)     # \u83b7\u53d6\u8be5\u8def\u5f84\u6587\u4ef6\u540d\u5217\u8868\n    print(&quot;\u539f\u59cb\u6587\u4ef6\u540d\u5217\u8868\u662f\uff1a&quot;, file_list0)\n    replace_head = name + &quot;.&quot; + season + &quot;E&quot;     # \u8bbe\u5b9a\u547d\u540d\u53c2\u6570\uff1ahead\n    replace_tail = &quot;&quot;                    # \u8bbe\u5b9a\u547d\u540d\u53c2\u6570:tail\n    for file0 in file_list0:\n        os.rename(file0, file0.replace(filename_head, replace_head)) # \u66ff\u6362\u6587\u4ef6\u5934:head\n    file_list1 = os.listdir(path_raw)      # \u91cd\u65b0\u83b7\u53d6\u8be5\u8def\u5f84\u6587\u4ef6\u540d\u5217\u8868\n    for file1 in file_list1:\n        os.rename(file1, file1.replace(filename_tail, replace_tail))   # \u66ff\u6362\u6587\u4ef6\u5c3e\uff1atail\n    file_list2 = os.listdir(path_raw)      # \u91cd\u65b0\u83b7\u53d6\u8be5\u8def\u5f84\u6587\u4ef6\u540d\u5217\u8868\n    print(&quot;\u6700\u7ec8\u6587\u4ef6\u540d\u5217\u8868\u662f\uff1a&quot;, file_list2)\n    for file2 in file_list2:\n        shutil.move(path_raw + &quot;\\\\&quot; + file2, path2) # \u79fb\u52a8\u6240\u6709\u6587\u4ef6\u5230\u76ee\u6807\u6587\u4ef6\u5939\n    print(&quot;\u547d\u540d\u5b8c\u6210\uff0c\u6587\u4ef6\u5df2\u7ecf\u79fb\u52a8\u5230\u76ee\u6807\u6587\u4ef6\u5939\u3002&quot;)\n    return\n\n# \u8c03\u7528\u51fd\u6570\nrename(name, season, filename_head, filename_tail)\n<\/code><\/pre>\n<hr \/>\n<h3>6.1.5 \u4ee3\u7801\u4f7f\u7528<\/h3>\n<ul>\n<li>\n<p>\u6839\u636e\u5267\u96c6\u4fe1\u606f\uff0c\u4fee\u6539\u53c2\u6570\uff1a<code>name<\/code>,<code>season<\/code>,<code>filename_head<\/code>,<code>filename_tail<\/code><\/p>\n<\/li>\n<li>\n<p>\u8bbe\u5b9a\u5267\u96c6<strong>\u5f85\u547d\u540d\u76ee\u5f55<\/strong>\uff0c\u5e76\u4fee\u6539\u53c2\u6570\uff1a<code>path_raw<\/code><\/p>\n<\/li>\n<li>\n<p>\u8bbe\u5b9a\u5267\u96c6<strong>\u6700\u7ec8\u5b58\u653e\u76ee\u5f55<\/strong>\uff0c\u5e76\u4fee\u6539\u53c2\u6570\uff1a<code>path_dest<\/code><\/p>\n<\/li>\n<li>\n<p><strong>\u786e\u4fdd\u5f85\u547d\u540d\u76ee\u5f55\u5185\u53ea\u6709\u5f85\u547d\u540d\u5267\u96c6\uff0c\u6ca1\u6709\u5176\u4ed6\u6587\u4ef6<\/strong>\u3002<\/p>\n<\/li>\n<li>\n<p>\u8fd0\u884c\u4e0a\u8ff0\u4ee3\u7801\uff0c\u83b7\u5f97\u8fd0\u884c\u6210\u529f\u63d0\u793a\u3002<\/p>\n<\/li>\n<li>\n<p>\u6253\u5f00\u5267\u96c6\u6700\u7ec8\u5b58\u653e\u76ee\u5f55\uff0c\u67e5\u770b\u662f\u5426\u6210\u529f\u547d\u540d\u3002<\/p>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>6.1 \u5267\u96c6\u6279\u91cf\u91cd\u547d\u540d 6.1.1 \u573a\u666f \u901a\u5e38\uff0c\u5728\u7ebf\u4e0b\u8f7d\u7684\u5267\u96c6\u6765\u6e90\u4e0d\u540c\uff0c\u6587\u4ef6\u547d\u540d\u4e94\u82b1\u516b\u95e8\uff0c\u9700\u8981\u91cd\u65b0\u547d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[29,30],"tags":[],"class_list":["post-4772","post","type-post","status-publish","format-standard","hentry","category-29","category-30"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/seit2019.xyz\/index.php?rest_route=\/wp\/v2\/posts\/4772","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/seit2019.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/seit2019.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/seit2019.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/seit2019.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4772"}],"version-history":[{"count":0,"href":"https:\/\/seit2019.xyz\/index.php?rest_route=\/wp\/v2\/posts\/4772\/revisions"}],"wp:attachment":[{"href":"https:\/\/seit2019.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4772"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seit2019.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4772"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seit2019.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4772"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}