使用Windows CMD行复制和重命名多个目录中的多个文件

时间:2017-04-25 03:59:21

标签: windows batch-file cmd copy rename

我想复制和重命名存储在一堆目录(年,月,日)中的文件。这些文件是<!DOCTYPE html> <html> <head> <link rel="stylesheet" type="text/css" href="Visitor.css"> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body> <script src="jquery-3.0.0.min.js"></script> <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script> <script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> </head> <style> .pop-outer{ background-color: rgba(0,0,0,0.5); position: fixed; top: 0%; left: 0%; width: 100%; height: 100%; } .pop-inner{ background-color: #fff; width: 500px; height: 500px; padding: 25px; margin: 15% auto; } </style> <script> $("document").ready(function(){ $(function() { $(".pop-outer").fadeIn('normal'); }); $(document).ready(function(){ $("close").click(function(event){ event.preventDefault(); }); }); });</script> <script> </script> </head> <body> <div class="pop-outer" > <div class="pop-inner ui-btn-icon-notext ui-btn-right"> <button onclick="close">X</button> <form action="visitor.php" method="post"> <div class="section"><span>1</span>Basic Information <div class="inner-wrap "> First Name <input type="text" placeholder="First Name"> Last Name <input type="text" placeholder="Last Name"> </div> </div> <div class="section"><span>2</span>Contact Information <div class="inner-wrap"> Email Address <input type="email" placeholder="Email Address"> Telephone Number <input type="number" placeholder="Phone Number"> </div> </div> <div class="section"><span>3</span>Visit Us <div class="inner-wrap"> When do you plan on visiting?<input type="date" placeholder="Select a date"> </div> </div> <div class="section"><span>4</span>Stay Connected <div class="inner-wrap"> Would you like to added to our email list?<br> <input type="radio" name="emailblast" value="Yes"> Yes! I would love to be connected with Hopewell! <input type="radio" name="emailblast" value="No"> No. I am not interested.</label> </div> </div> <div class="button-section"> <input type="submit"> </div> </form> </div> </div> 个文件,我需要它们来维护其扩展名,但要从.ers转到file.ers。 然后我希望给定月份的文件在每个月内保存在file_cloud.ers文件夹中。 理想情况下,我会在Windows命令行中执行此操作。 我理解批处理文件是一个很好的起点,所以我有以下内容 - 这不包括保存在不同的位置 - 但我正在努力只复制和重命名。

cloud

2 个答案:

答案 0 :(得分:0)

这可能比你做起来容易。如果回显正确的复制命令,请删除echo。你可以通过坚持到FOR /?的输出来实现这一点。

FOR /F "usebackq tokens=*" %%f IN (`DIR /S /B /A:-D "*.ers"`) DO (
    echo COPY "%%~f" "%%~dpnf_cloud.%%~xf"
)

答案 1 :(得分:0)

以下内容应该可以正常使用,(它应该将所有具有更新名称的匹配.ers文件复制到其树的上一级的现有云目录中)

@FOR /D %%Y IN ("C:\Data\20*") DO @FOR /D %%M IN ("%%Y\*"
) DO @FOR /D %%D IN ("%%M\*") DO @IF /I NOT "%%~nxD"=="cloud" FOR %%F IN (
    "%%~D\soig_*.ers") DO @COPY "%%F" "%%~M\cloud\%%~nFcloud%%~xF">NUL

我没有包含任何内容以防止覆盖名称已存在于该云目录中的文件

相关问题