{"id":1196,"date":"2010-09-23T18:01:17","date_gmt":"2010-09-23T18:01:17","guid":{"rendered":"http:\/\/ellery.no-ip.info\/wp\/thinkingmore\/2010\/09\/23\/%e8%87%aa%e5%8b%95%e5%88%86%e9%a1%9epdf%e8%88%87shutil\/"},"modified":"2015-01-08T16:35:36","modified_gmt":"2015-01-08T08:35:36","slug":"%e8%87%aa%e5%8b%95%e5%88%86%e9%a1%9epdf%e8%88%87shutil","status":"publish","type":"post","link":"https:\/\/ellery.no-ip.info\/wp\/thinkingmore\/2010\/09\/%e8%87%aa%e5%8b%95%e5%88%86%e9%a1%9epdf%e8%88%87shutil\/","title":{"rendered":"\u81ea\u52d5\u5206\u985epdf\u8207shutil"},"content":{"rendered":"<p>\u9019script\u4e3b\u8981\u662f\u5206\u985epdf\u7528\u7684\uff0c\u5f9e\u8b0e\u4e4b\u7db2\u7ad9\u4e0b\u8f09\u7684 pdf \u6a94\u6709\u898f\u5247\uff0c\u6240\u4ee5\u5c31\u53ef\u4ee5\u5bebcode\u4f86\u81ea\u52d5\u5206\u985e\u3002\u5bebscript\u6642\u767c\u73fe\u6709shutil\u9019\u500b\u5f88\u65b9\u4fbf\u7684\u6a21\u7d44\uff0c\u53ef\u4ee5\u7528\u4f86\u8907\u88fd\u3001\u642c\u79fb\u6a94\u6848\u3001\u76ee\u9304\u7b49\uff0c\u76f8\u7576\u7684\u65b9\u4fbf\uff0c\u539f\u672c\u9084\u4ee5\u70ba\u8981\u81ea\u5df1\u786c\u5e79\u54a7~<br \/>\n[python]#!\/usr\/bin\/env python<\/p>\n<h1>&#8211;<em>&#8211; coding: utf-8 &#8211;<\/em>&#8211;<\/h1>\n<p>def main():<br \/>\n  import glob<br \/>\n  import os<br \/>\n  import shutil<br \/>\n  files = glob.glob( &#8220;*.pdf&#8221; )<br \/>\n  for file_name in files:<br \/>\n    parts = file_name.split(&#8216;.&#8217;)<br \/>\n    index = -2<br \/>\n    while not parts[index].isdigit():<br \/>\n      index = index + 1<br \/>\n      dir_name = &#8221; &#8220;.join(parts[:index])<br \/>\n      if not os.path.exists(dir_name):<br \/>\n        os.mkdir(dir_name)<br \/>\n        try:<br \/>\n          print(&#8220;Move &#8216;%s&#8217; to &#8216;%s&#8217;.&#8221; % (<br \/>\n            file_name, os.path.join(dir_name, file_name)))<br \/>\n          shutil.move( file_name, os.path.join(dir_name, file_name))<br \/>\n        except shutil.Error, e:<br \/>\n          print(e)<\/p>\n<p>if <strong>name<\/strong> == &#8220;<strong>main<\/strong>&#8220;:<br \/>\n  main()<br \/>\n[\/python]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9019script\u4e3b\u8981\u662f\u5206\u985epdf\u7528\u7684\uff0c\u5f9e\u8b0e\u4e4b\u7db2\u7ad9\u4e0b\u8f09\u7684 pdf \u6a94\u6709\u898f\u5247\uff0c\u6240\u4ee5\u5c31\u53ef\u4ee5\u5bebcode\u4f86\u81ea\u52d5\u5206\u985e\u3002\u5bebscript\u6642\u767c\u73fe\u6709shutil\u9019\u500b\u5f88\u65b9\u4fbf\u7684\u6a21\u7d44\uff0c\u53ef\u4ee5\u7528\u4f86\u8907\u88fd\u3001\u642c\u79fb\u6a94\u6848\u3001\u76ee\u9304\u7b49\uff0c\u76f8\u7576\u7684\u65b9\u4fbf\uff0c\u539f\u672c\u9084\u4ee5\u70ba\u8981\u81ea\u5df1\u786c\u5e79\u54a7~ [python]#!\/usr\/bin\/env python &#8211;&#8211; coding: utf-8 &#8211;&#8211; def main(): import glob import os import shutil files = glob.glob( &#8220;*.pdf&#8221; ) for file_name in files: parts = file_name.split(&#8216;.&#8217;) index = -2 while not parts[index].isdigit(): index = index + 1 dir_name = &#8221; &#8220;.join(parts[:index]) if not os.path.exists(dir_name): os.mkdir(dir_name) try: print(&#8220;Move &#8216;%s&#8217; to &#8216;%s&#8217;.&#8221; % ( &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/ellery.no-ip.info\/wp\/thinkingmore\/2010\/09\/%e8%87%aa%e5%8b%95%e5%88%86%e9%a1%9epdf%e8%88%87shutil\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;\u81ea\u52d5\u5206\u985epdf\u8207shutil&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[17],"tags":[],"class_list":["post-1196","post","type-post","status-publish","format-standard","hentry","category-python"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2MOxp-ji","_links":{"self":[{"href":"https:\/\/ellery.no-ip.info\/wp\/thinkingmore\/wp-json\/wp\/v2\/posts\/1196","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ellery.no-ip.info\/wp\/thinkingmore\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ellery.no-ip.info\/wp\/thinkingmore\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ellery.no-ip.info\/wp\/thinkingmore\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ellery.no-ip.info\/wp\/thinkingmore\/wp-json\/wp\/v2\/comments?post=1196"}],"version-history":[{"count":2,"href":"https:\/\/ellery.no-ip.info\/wp\/thinkingmore\/wp-json\/wp\/v2\/posts\/1196\/revisions"}],"predecessor-version":[{"id":2567,"href":"https:\/\/ellery.no-ip.info\/wp\/thinkingmore\/wp-json\/wp\/v2\/posts\/1196\/revisions\/2567"}],"wp:attachment":[{"href":"https:\/\/ellery.no-ip.info\/wp\/thinkingmore\/wp-json\/wp\/v2\/media?parent=1196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ellery.no-ip.info\/wp\/thinkingmore\/wp-json\/wp\/v2\/categories?post=1196"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ellery.no-ip.info\/wp\/thinkingmore\/wp-json\/wp\/v2\/tags?post=1196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}