[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文件操作] [已解决]批处理怎样在多文件最后添加内容?

多文件最后添加内容?

多个文件夹:
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"

使用下面代码:
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. for /f "delims=" %%a in ('dir /a-d /b /s *.vmx') do (
  4.     pushd "%%~dpa"
  5.     (for /f "delims=" %%b in ('type "%%a"') do (
  6.         for %%i in (*.vmx) do echo "numvcpus = "4"" >>%%i
  7.         for %%i in (*.vmx) do echo "cpuid.coresPerSocket = "4"" >>%%i
  8.     ))
  9. )
复制代码
结果:重复添加了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"
....

  1. for /r %%i in (*.vmx)do (echo numvcpus = "4"&echo cpuid.coresPerSocket = "4")>>"%%i"
复制代码
1

评分人数

TOP

  1. for /f "delims=" %%i in ('dir /b/s *.vmx')do (echo numvcpus = "4"&echo cpuid.coresPerSocket = "4")>>"%%i"
复制代码
1

评分人数

TOP

返回列表