batch-file - 用于搜索和查找文件的批处理脚本,然后替换字符串
问题描述
尝试创建一个批处理脚本,该脚本可以在每个用户的配置文件中找到该文件,然后替换该文件中的某个字符串。该文件的位置是:C:\Users\%username%\AppData\Roaming\Sage Software\Sage MAS 500\application.config
我有后一部分工作,但不知道如何找到该文件。
@echo off
setlocal enabledelayedextensions
set "search= ^<ReportPath^>C:\Program Files ^(x86^)\Sage Software\Sage MAS 500 Client^</ReportPath^>"
set "replace=^<ReportPath^>\\bcshare.belterracorp.com\masreports^</ReportPath^>"
set "textFile=application.config"
for /f "delims=" %%i in ('type "%textFile%" ^& break ^> "%textFile%" ') do (
set "line=%%i"
setlocal enabledelayedexpansion
>>"%textFile%" echo(!line:%search%=%replace%!
endlocal
)
解决方案
推荐阅读
- sql - 滚动日期范围内的 BigQuery 不同计数,列分区
- c# - Moq 与 LINQ 到实体投影
- c# - 如何实现一个只包含预定义内容但仍然可以编组的结构?
- python - Azure ML 环境的自定义 Docker 文件,其中包含 COPY 语句错误,COPY 失败:/path 没有这样的文件或目录
- ios - 如何在点击按钮时将 Tableview 单元格内的文本字段中的数据打印到控制台
- r - 使用条件聚合行
- fb-hydra - 使用 Hydra 从 Python 代码中可见的“overrides.yaml”的路径是什么
- javascript - 只交出一些额外的函数变量
- javascript - 使用 reactjs 中的道具从孩子传递数据
- javascript - 通过单击jquery中的外部按钮向上或向下移动表行时如何修复特定列值