我需要将文件中定义的路径更改为我想要的路径位置,即duster.properties。
文件,即duster.properties内容:-
com.test.import.uploadDirectory=C:\\progra~2\\Test\\Demo\\jboss7\\standalone\\uploads
com.test.import.maxFilesUploadNumber=10
com.test.etl.pluginsRootDirectory=C:\\progra~2\\Test\\Demo\\jboss7\\standalone\\cloverETL\
\plugins
com.test.etl.templatesDirectory=C:\\progra~2\\Test\\Demo\\jboss7\\standalone\\etl
com.test.db.user=postgres
com.test.db.pass=password
com.test.addressdoctor.customerID=149374
com.test.addressdoctor.password=apr2511
com.test.addressdoctor.maxi.customerID=146890正如您在duster.properties中看到的,位置是硬编码的
C:\\progra~2\\Test\\Demo\\jboss7\\standalone\\uploads但我可以在系统中的任何地方找到我的jboss7位置,即C盘或D盘。
我可以搜索jboss7的位置,并使用以下代码将其路径设置为变量名,即'folderLocation‘。
@echo off
for /f "delims=" %%a in (' dir "c:\jboss7" /b /s /ad ') do if /i "%%~nxa"=="jboss7" set
"folderLocation=%%a"
if not defined folderLocation for /f "delims=" %%a in (' dir "d:\jboss7" /b /s /ad ')
do if /i "%%~nxa"=="jboss7" set "folderLocation=%%a"
echo "%folderLocation%"
pause现在我想要的是编辑文件,并将变量folderLocation设置为路径,或者简单地说,查找并替换路径。
. e.g:-'folderLocation'\\standalone\\uploads在duster.properties的每一条道路上都像wise一样。在批处理脚本中是可能的吗?实际上,我对批处理脚本并没有很好的了解。
任何帮助都将受到高度的感谢。
发布于 2013-09-20 14:50:52
这与示例数据一起使用,并使用来自- http://www.dostips.com/forum/viewtopic.php?f=3&t=3855的名为repl.bat的帮助程序批处理文件
@echo off
set "newpath=d:\\stuff\\and\\widgets"
type "duster.properties" | repl "(Directory=).*(\\\\standalone\\\\)" "$1%newpath%$2" >"duster.properties.tmp"
move "duster.properties.tmp" "duster.properties"发布于 2021-05-06 19:34:33
使用父路径方法文件currentPath =新文件(dir.getParent()) String currentFolder= currentPath.getName().toString()
https://stackoverflow.com/questions/18909597
复制相似问题