用新文件替换旧文件 [英] Replace old file with new file
问题描述
我正在尝试编写一个脚本,用以下格式出现的新文件内容替换旧文件内容:
I am trying to write a script to replace old files content with new files content which is appearing in the following format:
旧文件:something.txt
新文件:something.txt.new
Old file : something.txt
New file : something.txt.new
旧文件需要替换为新文件内容
要重命名的新文件名,而无需新建
旧文件需要删除
Old file need to replaced with New file contents
New File name to be rename without new
Old file need to be deleted
以下脚本不起作用:请重写:
Below script is not working :Could you please rewrite:
@echo off
setlocal enabledelayedexpansion
set FOLDER_PATH=D:\test
for %%f in (%FOLDER_PATH%*) do if %%f neq %~nx0 (
set basename=test
ren *.txt.new !basename!.txt
)
PAUSE
我的文件夹中有很多文件,需要遍历每个文件,只需要在每次迭代中用旧文件名填充basename变量即可.
i have many files in folder and need to iterate through each file,only i need is basename variable need to be filled with the name of the old file name in each iteration
推荐答案
无效的问题无效的答案
源1
@echo off
set FOLDER_PATH=D:\test
cd /d "%FOLDER_PATH%"
ren "*.txt.new" "*.txt"
源2
@echo off
set FOLDER_PATH=D:\test
cd /d "%FOLDER_PATH%"
ren "*.txt" "*.txt.new"
这篇关于用新文件替换旧文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!