标题: [文件操作] [已解决]批处理怎样在多文件最后添加内容? [打印本页]
作者: 滴血雄鹰 时间: 2021-3-21 13:07 标题: [已解决]批处理怎样在多文件最后添加内容?
多文件最后添加内容?
多个文件夹:
1001\1001.vmx
1002\1002.vmx
...
1400\1400.vmx
...
2001\2001.vmx
2002\2002.vmx
...
2400\2400.vmx
...
想要在本文件夹及子文件夹中后缀为vmx的文件的最后,添加下面二行内容:
numvcpus = "4"
cpuid.coresPerSocket = "4"
想要实现效果:
ethernet0.address = "00:50:56:07:00:02"
numvcpus = "4"
cpuid.coresPerSocket = "4"
使用下面代码:- @echo off
- setlocal enabledelayedexpansion
- for /f "delims=" %%a in ('dir /a-d /b /s *.vmx') do (
- pushd "%%~dpa"
- (for /f "delims=" %%b in ('type "%%a"') do (
- for %%i in (*.vmx) do echo "numvcpus = "4"" >>%%i
- for %%i in (*.vmx) do echo "cpuid.coresPerSocket = "4"" >>%%i
- ))
- )
复制代码
结果:重复添加了97次,变成
ethernet0.address = "00:50:56:07:00:02"
numvcpus = "4"
cpuid.coresPerSocket = "4"
numvcpus = "4"
cpuid.coresPerSocket = "4"
numvcpus = "4"
cpuid.coresPerSocket = "4"
numvcpus = "4"
cpuid.coresPerSocket = "4"
numvcpus = "4"
cpuid.coresPerSocket = "4"
....
作者: smss 时间: 2021-3-21 13:42
- for /f "delims=" %%i in ('dir /b/s *.vmx')do (echo numvcpus = "4"&echo cpuid.coresPerSocket = "4")>>"%%i"
复制代码
作者: smss 时间: 2021-3-21 13:44
- for /r %%i in (*.vmx)do (echo numvcpus = "4"&echo cpuid.coresPerSocket = "4")>>"%%i"
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |