简体   繁体   English

使用批处理文件重命名文件夹路径中的文件名

[英]rename the file name in a folder path using batch file

Below is the bat file: 下面是bat文件:

@echo off
set "D=%date%"
echo "%D%"
ren "D:\empty\ EE_DG3-ERROR.txt" "D:\empty\ EE_DG3-ERROR_%D%.txt"
pause

I want to append the datetime to the filename. 我想将日期时间附加到文件名中。

example : D:\\empty\\ EE_DG3-ERROR.txt to D:\\empty\\ EE_DG3-ERROR_14oct2013.txt 例如: D:\\ empty \\ EE_DG3-ERROR.txt到D:\\ empty \\ EE_DG3-ERROR_14oct2013.txt

can you please help me with your suggestions? 你能帮我的建议吗?

ren "D:\empty\EE_DG3-ERROR.txt" "EE_DG3-ERROR_%date:/=_%-%time::=_%.txt"

edited to give a month name 编辑以提供月份名称

This isn't quite the format you asked for either: But the first four lines of this code will give you reliable YY DD MM YYYY HH Min Sec variables in XP Pro and higher. 这也不完全是您要求的格式:但是此代码的前四行将为您提供XP Pro及更高版本中可靠的YY DD MM YYYY HH Min Sec变量。

@echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"


if "%mm%"=="01" set "mmm=Jan"
if "%mm%"=="02" set "mmm=Feb"
if "%mm%"=="03" set "mmm=Mar"
if "%mm%"=="04" set "mmm=Apr"
if "%mm%"=="05" set "mmm=May"
if "%mm%"=="06" set "mmm=Jun"
if "%mm%"=="07" set "mmm=Jul"
if "%mm%"=="08" set "mmm=Aug"
if "%mm%"=="09" set "mmm=Sep"
if "%mm%"=="10" set "mmm=Oct"
if "%mm%"=="11" set "mmm=Nov"
if "%mm%"=="12" set "mmm=Dec"

set "fullstamp=%DD%%mmm%%YYYY%"

for %%a in ("D:\empty\EE_DG3-ERROR.txt") do ren "%%~a" "%%~na_%fullstamp%%%~xa"
for %%a in ("D:\empty\plot.log")         do ren "%%~a" "%%~na_%fullstamp%%%~xa"

try this, 尝试这个,

set dirpath=D:\empty\
ren "%dirpath%EE_DG3-ERROR.txt" EE_DG3-ERROR_14102013.txt

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 批处理文件移动并将文件夹重命名为相对路径 - batch file to move and rename folder to a relative path Windows Batch:将文件夹重命名为其中的文件名 - Windows Batch: Rename a folder to the name of a file inside 从批处理文件的路径中提取文件夹名称 - Extract folder name from path in batch file 如何将文件批量重命名为父级的父文件夹名称 - How to rename a file to the parent's parent folder name in batch 使用原始名称的部分文本重命名文件夹中的文件(批处理文件,powershell,其他解决方案) - Rename files in a folder using part of text of original name (batch file, powershell, other solution) 使用批处理文件更改文件夹名称 - Change folder name using batch file 将文件夹名称附加到文件名并使用DOS批处理移动文件 - Append folder name to file name and move file using DOS batch 在目录/子目录中生成文件夹 list.txt 文件并在批处理文件中使用 dir & ren 命令将 list.txt 重命名为文件夹/子文件夹名称 - Generate file-folder list.txt file in a directory/subdirectory & rename list.txt to folder/subfolder name using dir & ren command in a batch file 从批处理文件中的路径获取文件夹名称。 没有解决 - Get folder name from path in batch file. Not resolving 使用批处理编程在文件路径中重命名具有特定文件夹名称的文件 - Renaming files with specific folder name in a file path with batch programming
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM