{"id":217339,"date":"2021-05-14T09:25:19","date_gmt":"2021-05-14T01:25:19","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=217339"},"modified":"2021-04-26T10:27:18","modified_gmt":"2021-04-26T02:27:18","slug":"windows-bat-for","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/windows-bat-for.html","title":{"rendered":"Windows bat\u811a\u672c\u4e4bfor\u5faa\u73af\u7528\u6cd5"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u4e86Windows bat\u811a\u672c\u4e4bfor\u5faa\u73af\u7528\u6cd5\u8be6\u89e3,\u672c\u6587\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u7684\u975e\u5e38\u8be6\u7ec6\uff0c\u5bf9\u5927\u5bb6\u7684\u5b66\u4e60\u6216\u5de5\u4f5c\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u501f\u9274\u4ef7\u503c<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

Windows bat\u811a\u672c\u7684for\u8bed\u53e5\u57fa\u672c\u5f62\u6001\u5982\u4e0b\uff1a<\/p>\n

\r\n\u5728cmd\u7a97\u53e3\u4e2d\uff1afor %I in (command1) do command2 \r\n\u5728\u6279\u5904\u7406\u6587\u4ef6\u4e2d\uff1afor %%I in (command1) do command2\r\n<\/pre>\n

\u4e4b\u6240\u4ee5\u8981\u533a\u5206cmd\u7a97\u53e3\u548c\u6279\u5904\u7406\u6587\u4ef6\u4e24\u79cd\u73af\u5883\uff0c\u662f\u56e0\u4e3a\u5728\u8fd9\u4e24\u79cd\u73af\u5883\u4e0b\uff0c\u547d\u4ee4\u8bed\u53e5\u8868\u73b0\u51fa\u6765\u7684\u884c\u4e3a\u867d\u7136\u57fa\u672c\u4e00\u6837\uff0c\u4f46\u662f\u5728\u7ec6\u8282\u4e0a\u8fd8\u662f\u7a0d\u6709\u4e0d\u540c\uff0c\u6700\u660e\u663e\u7684\u4e00\u4e2a\u5dee\u5f02\u5c31\u662f\uff1a\u5728cmd\u7a97\u53e3\u4e2d\uff0cfor\u4e4b\u540e\u7684\u5f62\u5f0f\u53d8\u91cfI\u5fc5\u987b\u4f7f\u7528\u5355\u767e\u5206\u53f7\u5f15\u7528\uff0c\u5373%I\uff1b\u800c\u5728\u6279\u5904\u7406\u6587\u4ef6\u4e2d\uff0c\u5f15\u7528\u5f62\u5f0f\u53d8\u91cfI\u5fc5\u987b\u4f7f\u7528\u53cc\u767e\u5206\u53f7\uff0c\u5373%%I\u3002\u4e3a\u4e86\u65b9\u4fbf\u8d77\u89c1\uff0c\u82e5\u4e0d\u662f\u7279\u522b\u5f3a\u8c03\uff0c\u4ee5\u4e0b\u7684\u8bb2\u89e3\u90fd\u4ee5\u6279\u5904\u7406\u6587\u4ef6\u73af\u5883\u4e3a\u4f8b\u3002<\/p>\n

\u6211\u4eec\u5148\u6765\u770b\u4e00\u4e0bfor\u8bed\u53e5\u7684\u57fa\u672c\u8981\u7d20\u90fd\u6709\u4e9b\u4ec0\u4e48\uff1a<\/p>\n

    \n
  • for\u3001in\u548cdo\u662ffor\u8bed\u53e5\u7684\u5173\u952e\u5b57\uff0c\u5b83\u4eec\u4e09\u4e2a\u7f3a\u4e00\u4e0d\u53ef\uff1b<\/li>\n
  • %%I\u662ffor\u8bed\u53e5\u4e2d\u5bf9\u5f62\u5f0f\u53d8\u91cf\u7684\u5f15\u7528\uff0c\u5373\u4f7f\u53d8\u91cfl\u5728do\u540e\u7684\u8bed\u53e5\u4e2d\u6ca1\u6709\u53c2\u4e0e\u8bed\u53e5\u7684\u6267\u884c\uff0c\u4e5f\u662f\u5fc5\u987b\u51fa\u73b0\u7684\uff1b<\/li>\n
  • in\u4e4b\u540e\uff0cdo\u4e4b\u524d\u7684\u62ec\u53f7\u4e0d\u80fd\u7701\u7565\uff1b<\/li>\n
  • command1\u8868\u793a\u5b57\u7b26\u4e32\u6216\u53d8\u91cf\uff0ccommand2\u8868\u793a\u5b57\u7b26\u4e32\u3001\u53d8\u91cf\u6216\u547d\u4ee4\u8bed\u53e5\uff1b<\/li>\n<\/ul>\n

    \u4e0b\u9762\u6765\u770b\u4e00\u4e2aWindows bat\u811a\u672c\u7684demo(\u8bb0\u4e3ademo1)\uff1a<\/p>\n

    \r\n@echo off\r\nfor %%I in (ABC) do echo %%I\r\npause\r\n<\/pre>\n

    \u4fdd\u5b58\u4e3a.bat\u6587\u4ef6(\u6279\u5904\u7406\u6587\u4ef6)\u5e76\u6267\u884c\uff0c\u5c06\u4f1a\u5728\u5f39\u51fa\u7684\u6279\u5904\u7406\u7a97\u53e3\u4e2d\u770b\u5230\u8fd9\u6837\u7684\u4fe1\u606f\uff1a
    \n\"\"<\/p>\n

    \u5bf9\u6279\u5904\u7406\u6587\u4ef6\u7684for\u5faa\u73af\u5c31\u662f\u8fd9\u6837\u7b80\u5355\uff0c\u4e0b\u9762\u6765\u770b\u770bfor\u8bed\u53e5\u7684\u6ce8\u610f\u4e8b\u9879\uff0c\u5e76\u8fd0\u884c\u66f4\u590d\u6742\u7684for\u5faa\u73af\u5b9e\u4f8b\u3002<\/p>\n

      \n
    • for\u8bed\u53e5\u7684\u5f62\u5f0f\u53d8\u91cfI\uff0c\u53ef\u4ee5\u6362\u621026\u4e2a\u5b57\u6bcd\u4e2d\u7684\u4efb\u610f\u4e00\u4e2a\uff0c\u8fd9\u4e9b\u5b57\u6bcd\u4f1a\u533a\u5206\u5927\u5c0f\u5199\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c%%I\u548c%%i\u4f1a\u88ab\u8ba4\u4e3a\u4e0d\u662f\u540c\u4e00\u4e2a\u53d8\u91cf\uff1b\u5f62\u5f0f\u53d8\u91cfI\u8fd8\u53ef\u4ee5\u6362\u6210\u5176\u4ed6\u7684\u5b57\u7b26\uff0c\u4f46\u662f\uff0c\u4e3a\u4e86\u4e0d\u4e0e\u6279\u5904\u7406\u4e2d\u7684%0\uff5e%9\u8fd910\u4e2a\u5f62\u5f0f\u53d8\u91cf\u53d1\u751f\u51b2\u7a81\uff0c\u8bf7\u4e0d\u8981\u968f\u610f\u628a%%I\u66ff\u6362\u4e3a%%0\uff5e%%9\u4e2d\u7684\u4efb\u610f\u4e00\u4e2a\uff1b<\/li>\n
    • in\u548cdo\u4e4b\u95f4\u7684command1\u8868\u793a\u7684\u5b57\u7b26\u4e32\u6216\u53d8\u91cf\u53ef\u4ee5\u662f\u4e00\u4e2a\uff0c\u4e5f\u53ef\u4ee5\u662f\u591a\u4e2a\uff0c\u6bcf\u4e00\u4e2a\u5b57\u7b26\u4e32\u6216\u53d8\u91cf\uff0c\u6211\u4eec\u79f0\u4e4b\u4e3a\u4e00\u4e2a\u5143\u7d20\uff0c\u6bcf\u4e2a\u5143\u7d20\u4e4b\u95f4\uff0c\u7528\u7a7a\u683c\u952e\u3001\u8df3\u683c\u952e\u3001\u9017\u53f7\u3001\u5206\u53f7\u6216\u7b49\u53f7\u5206\u9694\uff1b<\/li>\n
    • for\u8bed\u53e5\u4f9d\u6b21\u63d0\u53d6command1\u4e2d\u7684\u6bcf\u4e00\u4e2a\u5143\u7d20\uff0c\u628a\u5b83\u7684\u503c\u8d4b\u4e88\u5f62\u5f0f\u53d8\u91cfI\uff0c\u5e26\u5230do\u540e\u7684command2\u4e2d\u53c2\u4e0e\u547d\u4ee4\u7684\u6267\u884c\uff1b\u5e76\u4e14\u6bcf\u6b21\u53ea\u63d0\u53d6\u4e00\u4e2a\u5143\u7d20\uff0c\u7136\u540e\u6267\u884c\u4e00\u6b21do\u540e\u7684\u547d\u4ee4\u8bed\u53e5\uff0c\u800c\u65e0\u8bba\u8fd9\u4e2a\u5143\u7d20\u662f\u5426\u88ab\u5e26\u5230command2\u4e2d\u53c2\u4e0e\u4e86command2\u7684\u8fd0\u884c\uff1b\u5f53\u6267\u884c\u5b8c\u4e00\u6b21do\u540e\u7684\u8bed\u53e5\u4e4b\u540e\uff0c\u518d\u63d0\u53d6command1\u4e2d\u7684\u4e0b\u4e00\u4e2a\u5143\u7d20\uff0c\u518d\u6267\u884c\u4e00\u6b21command2\uff0c\u5982\u6b64\u5faa\u73af\uff0c\u76f4\u5230command1\u4e2d\u7684\u6240\u6709\u5143\u7d20\u90fd\u5df2\u7ecf\u88ab\u63d0\u53d6\u5b8c\u6bd5\uff0c\u8be5for\u8bed\u53e5\u624d\u5ba3\u544a\u6267\u884c\u7ed3\u675f\u3002<\/li>\n<\/ul>\n

      \u6709\u4e86\u4ee5\u4e0a\u7684\u57fa\u7840\uff0c\u6211\u4eec\u518d\u6765\u770b\u4e0b\u9762\u8fd9\u4e2a\u4f8b\u5b50\uff0c\u8fd9\u4e2a\u4f8b\u5b50\u4fee\u6539\u4e86demo1\u4e2d\u7684\u90e8\u5206\u5185\u5bb9(\u8bb0\u4e3ademo2)\uff0c\u7ed3\u679c\u5c06\u5927\u4e0d\u4e00\u6837\uff1a<\/p>\n

      \r\n@echo off\r\nfor %%I in (A,B,C) do echo %%I\r\npause\r\n<\/pre>\n

      \u8fd0\u884c\u7ed3\u679c\u5982\u4e0b\uff1a
      \n\"\"<\/p>\n

      \u5982\u679c\u628a bbs.bathome.cn \u8fd9\u4e2a\u5b57\u7b26\u4e32\u4e2d\u7684\u70b9\u53f7\u6362\u4e3a\u7a7a\u683c\u3001\u8df3\u683c\u6216\u7b49\u53f7\uff0c\u6267\u884c\u7ed3\u679c\u5c06\u548cdemo2\u7684\u6267\u884c\u7ed3\u679c\u522b\u65e0\u4e8c\u81f4\u3002<\/p>\n

      \u73b0\u5728\uff0c\u6765\u5206\u6790\u4e00\u4e0bdemo2\u4ee3\u7801\u4e2dfor\u8bed\u53e5\u7684\u6267\u884c\u8fc7\u7a0b\uff1a<\/p>\n

        \n
      • 1.for\u8bed\u53e5\u4ee5\u9017\u53f7\u4e3a\u5206\u9694\u7b26\uff0c\u628a A,B,C \u8fd9\u4e2a\u5b57\u7b26\u4e32\u5207\u5206\u6210\u4e09\u4e2a\u5143\u7d20\uff1aA\u3001B\u548cC\uff0c\u7531\u6b64\u51b3\u5b9a\u4e86do\u540e\u7684\u8bed\u53e5\u5c06\u4f1a\u88ab\u6267\u884c3\u6b21\uff1b <\/li>\n
      • 2.\u7b2c\u4e00\u6b21\u6267\u884c\u8fc7\u7a0b\u662f\u8fd9\u6837\u7684\uff1a\u5148\u628a bbs \u8fd9\u4e2a\u5b57\u7b26\u4e32\u4f5c\u4e3a\u5f62\u5f0f\u53d8\u91cfI\u7684\u503c\uff0c\u5e26\u5165do\u540e\u7684\u8bed\u53e5\u4e2d\u52a0\u4ee5\u6267\u884c\uff0c\u4e5f\u5c31\u662f\u6267\u884c echo %%I \u8bed\u53e5\uff0c\u6b64\u65f6\u7684I\u503c\u4e3aA\uff0c\u56e0\u6b64\uff0c\u7b2c\u4e00\u6b21\u6267\u884c\u7684\u7ed3\u679c\uff0c\u5c06\u4f1a\u5728\u5c4f\u5e55\u4e0a\u663e\u793aA\u8fd9\u4e2a\u5b57\u7b26\u4e32\uff1b\u7b2c\u4e8c\u6b21\u6267\u884c\u548c\u7b2c\u4e00\u6b21\u6267\u884c\u7684\u8fc7\u7a0b\u662f\u4e00\u6837\u7684\uff0c\u53ea\u4e0d\u8fc7\u6b64\u65f6I\u7684\u503c\u5df2\u7ecf\u88ab\u66ff\u6362\u4e3acommand1\u4e2d\u7684\u7b2c\u4e8c\u4e2a\u5143\u7d20\u4e86\uff0c\u4e5f\u5c31\u662f B \u8fd9\u4e2a\u5b57\u7b26\u4e32\uff1b\u5982\u6b64\u5faa\u73af\uff0c\u5f53\u7b2c\u4e09\u6b21echo\u6267\u884c\u5b8c\u6bd5\u4e4b\u540e\uff0c\u6574\u6761for\u8bed\u53e5\u624d\u7b97\u6267\u884c\u5b8c\u6bd5\uff0c\u6b64\u65f6\uff0c\u5c06\u6267\u884c\u4e0b\u4e00\u6761\u8bed\u53e5\uff0c\u4e5f\u5c31\u662fpause\u547d\u4ee4\u3002<\/li>\n<\/ul>\n

        \u9ad8\u7ea7\u7528\u6cd5\uff1a<\/p>\n

        1)\u641c\u7d22\u5f53\u524d\u76ee\u5f55\u4e0b\u6709\u54ea\u4e9b\u6587\u4ef6\uff1f<\/p>\n

        \r\n@echo off\r\nfor %%i in (*.*) do echo \"%%i\"\r\npause\r\n<\/pre>\n

        2)\u641c\u7d22\u5f53\u524d\u76ee\u5f55\u4e0b\u6240\u6709\u7684\u6587\u672c\u6587\u4ef6\uff1f<\/p>\n

        \r\n@echo off\r\nfor %%i in (*.txt) do echo \"%%i\"\r\npause\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

        Windows bat\u811a\u672c\u7684for\u8bed\u53e5\u57fa\u672c\u5f62\u6001\u5982\u4e0b\uff1a \u5728cmd\u7a97\u53e3\u4e2d\uff1afor %I in (command1) […]<\/p>\n","protected":false},"author":1479,"featured_media":119364,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-217339","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/217339","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1479"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=217339"}],"version-history":[{"count":2,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/217339\/revisions"}],"predecessor-version":[{"id":217343,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/217339\/revisions\/217343"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/119364"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=217339"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=217339"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=217339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}