{"id":586,"date":"2024-11-24T09:05:50","date_gmt":"2024-11-24T01:05:50","guid":{"rendered":"https:\/\/blog.yuekegu.com\/?p=586"},"modified":"2024-11-24T09:05:50","modified_gmt":"2024-11-24T01:05:50","slug":"%e5%9c%a8%e5%8e%9f%e6%96%87%e4%bb%b6%e5%90%8d%e5%89%8d%e5%8a%a0%e4%b8%8a%e5%89%8d%e7%bc%80%e5%b9%b6%e5%ae%9e%e7%8e%b0%e6%96%87%e4%bb%b6%e7%9a%84%e6%89%b9%e9%87%8f%e9%87%8d%e5%91%bd%e5%90%8d","status":"publish","type":"post","link":"https:\/\/book.yuekegu.com\/index.php\/2024\/11\/24\/%e5%9c%a8%e5%8e%9f%e6%96%87%e4%bb%b6%e5%90%8d%e5%89%8d%e5%8a%a0%e4%b8%8a%e5%89%8d%e7%bc%80%e5%b9%b6%e5%ae%9e%e7%8e%b0%e6%96%87%e4%bb%b6%e7%9a%84%e6%89%b9%e9%87%8f%e9%87%8d%e5%91%bd%e5%90%8d\/","title":{"rendered":"\u5728\u539f\u6587\u4ef6\u540d\u524d\u52a0\u4e0a\u524d\u7f00\u5e76\u5b9e\u73b0\u6587\u4ef6\u7684\u6279\u91cf\u91cd\u547d\u540d"},"content":{"rendered":"\n<p>\u8981\u5728\u539f\u6587\u4ef6\u540d\u524d\u52a0\u4e0a\u524d\u7f00\u5e76\u5b9e\u73b0\u6587\u4ef6\u7684\u6279\u91cf\u91cd\u547d\u540d\uff0c\u4f60\u53ef\u4ee5\u6839\u636e\u4f60\u6240\u4f7f\u7528\u7684\u64cd\u4f5c\u7cfb\u7edf\u9009\u62e9\u5408\u9002\u7684\u811a\u672c\u8bed\u8a00\u6765\u7f16\u5199\u811a\u672c\u3002\u4ee5\u4e0b\u662f\u5728\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd\u7684\u793a\u4f8b\uff1a<\/p>\n\n\n\n<p>\u5728 Windows \u4e0a\u4f7f\u7528 PowerShell<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u8bbe\u7f6e\u6587\u4ef6\u5939\u8def\u5f84\n$folderPath = \"C:\\path\\to\\your\\folder\"\n\n# \u8bbe\u7f6e\u524d\u7f00\n$prefix = \"prefix_\"\n\n# \u83b7\u53d6\u6587\u4ef6\u5939\u4e2d\u7684\u6240\u6709\u6587\u4ef6\n$files = Get-ChildItem -Path $folderPath\n\n# \u904d\u5386\u5e76\u91cd\u547d\u540d\u6bcf\u4e2a\u6587\u4ef6\nforeach ($file in $files) {\n    # \u6784\u9020\u65b0\u7684\u6587\u4ef6\u540d\n    $newName = $prefix + $file.Name\n    # \u91cd\u547d\u540d\u6587\u4ef6\n    Rename-Item -Path $file.FullName -NewName (Join-Path $folderPath $newName)\n}<\/code><\/pre>\n\n\n\n<p>\u5728 macOS\/Linux \u4e0a\u4f7f\u7528 Shell \u811a\u672c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n\n# \u8bbe\u7f6e\u6587\u4ef6\u5939\u8def\u5f84\nfolder_path=\"\/path\/to\/your\/folder\"\n\n# \u8bbe\u7f6e\u524d\u7f00\nprefix=\"prefix_\"\n\n# \u8fdb\u5165\u6587\u4ef6\u5939\ncd \"$folder_path\"\n\n# \u904d\u5386\u5e76\u91cd\u547d\u540d\u6bcf\u4e2a\u6587\u4ef6\nfor file in *; do\n  if &#91; -f \"$file\" ]; then\n    new_name=\"${prefix}${file}\"\n    mv \"$file\" \"$new_name\"\n  fi\ndone\n<\/code><\/pre>\n\n\n\n<p>\u5728 Python \u4e2d\u4f7f\u7528 os \u6a21\u5757<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import os\n\n# \u8bbe\u7f6e\u6587\u4ef6\u5939\u8def\u5f84\nfolder_path = '\/path\/to\/your\/folder'\n\n# \u8bbe\u7f6e\u524d\u7f00\nprefix = 'prefix_'\n\n# \u83b7\u53d6\u6587\u4ef6\u5939\u4e2d\u7684\u6240\u6709\u6587\u4ef6\nfiles = os.listdir(folder_path)\n\n# \u904d\u5386\u5e76\u91cd\u547d\u540d\u6bcf\u4e2a\u6587\u4ef6\nfor file_name in files:\n    if os.path.isfile(os.path.join(folder_path, file_name)):\n        new_name = prefix + file_name\n        os.rename(os.path.join(folder_path, file_name), os.path.join(folder_path, new_name))<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u6ce8\u610f\u4e8b\u9879<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u786e\u4fdd\u4f60\u6709\u6743\u9650<\/strong>\uff1a\u5728\u91cd\u547d\u540d\u6587\u4ef6\u4e4b\u524d\uff0c\u786e\u4fdd\u4f60\u6709\u8db3\u591f\u7684\u6743\u9650\u6765\u4fee\u6539\u6587\u4ef6\u540d\u3002<\/li>\n\n\n\n<li><strong>\u907f\u514d\u547d\u540d\u51b2\u7a81<\/strong>\uff1a\u5982\u679c\u6dfb\u52a0\u524d\u7f00\u540e\u53ef\u80fd\u5bfc\u81f4\u6587\u4ef6\u540d\u51b2\u7a81\uff08\u4f8b\u5982\uff0c\u539f\u6587\u4ef6\u4e2d\u5df2\u7ecf\u5b58\u5728\u4ee5\u8be5\u524d\u7f00\u5f00\u5934\u7684\u6587\u4ef6\uff09\uff0c\u4f60\u9700\u8981\u8003\u8651\u5982\u4f55\u5904\u7406\u8fd9\u79cd\u60c5\u51b5\uff0c\u6bd4\u5982\u68c0\u67e5\u65b0\u6587\u4ef6\u540d\u662f\u5426\u5df2\u5b58\u5728\uff0c\u6216\u8005\u6dfb\u52a0\u989d\u5916\u7684\u5e8f\u53f7\u6765\u907f\u514d\u51b2\u7a81\u3002<\/li>\n\n\n\n<li><strong>\u6d4b\u8bd5\u811a\u672c<\/strong>\uff1a\u5728\u6b63\u5f0f\u8fd0\u884c\u811a\u672c\u4e4b\u524d\uff0c\u6700\u597d\u5728\u4e00\u4e2a\u5305\u542b\u5c11\u91cf\u6d4b\u8bd5\u6587\u4ef6\u7684\u6587\u4ef6\u5939\u4e2d\u6d4b\u8bd5\u811a\u672c\uff0c\u4ee5\u786e\u4fdd\u5b83\u6309\u9884\u671f\u5de5\u4f5c\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u5c06\u4e0a\u8ff0\u811a\u672c\u4e2d\u7684&nbsp;<code>folder_path<\/code>&nbsp;\u6216&nbsp;<code>$folderPath<\/code>&nbsp;\u66ff\u6362\u4e3a\u4f60\u7684\u6587\u4ef6\u5939\u8def\u5f84\uff0c\u5c06&nbsp;<code>prefix<\/code>&nbsp;\u66ff\u6362\u4e3a\u4f60\u60f3\u8981\u6dfb\u52a0\u7684\u524d\u7f00\uff0c\u7136\u540e\u8fd0\u884c\u811a\u672c\u5373\u53ef\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8981\u5728\u539f\u6587\u4ef6\u540d\u524d\u52a0\u4e0a\u524d\u7f00\u5e76\u5b9e\u73b0\u6587\u4ef6\u7684\u6279\u91cf\u91cd\u547d\u540d\uff0c\u4f60\u53ef\u4ee5\u6839\u636e\u4f60\u6240\u4f7f\u7528\u7684\u64cd\u4f5c\u7cfb\u7edf\u9009\u62e9\u5408\u9002\u7684\u811a\u672c\u8bed\u8a00\u6765\u7f16\u5199\u811a\u672c\u3002\u4ee5\u4e0b\u662f\u5728\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd\u7684\u793a\u4f8b\uff1a \u5728 Windows \u4e0a\u4f7f\u7528 PowerShell \u5728 macOS\/Linux \u4e0a\u4f7f\u7528 Shell \u811a\u672c \u5728 Python \u4e2d\u4f7f\u7528 os \u6a21\u5757 \u6ce8\u610f\u4e8b\u9879 \u5c06\u4e0a\u8ff0\u811a\u672c\u4e2d\u7684&nbsp;folder_path&nbsp;\u6216&nbsp;$folderPath&nbsp;\u66ff\u6362\u4e3a\u4f60\u7684\u6587\u4ef6\u5939\u8def\u5f84\uff0c\u5c06&nbsp;prefix&nbsp;\u66ff\u6362\u4e3a\u4f60\u60f3\u8981\u6dfb\u52a0\u7684\u524d\u7f00\uff0c\u7136\u540e\u8fd0\u884c\u811a\u672c\u5373\u53ef\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,27],"tags":[],"class_list":["post-586","post","type-post","status-publish","format-standard","hentry","category-python","category-27"],"_links":{"self":[{"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/posts\/586","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/comments?post=586"}],"version-history":[{"count":0,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/posts\/586\/revisions"}],"wp:attachment":[{"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/media?parent=586"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/categories?post=586"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/tags?post=586"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}