Batch file 将硬编码路径更改为我想要的路径
我需要使用所需的路径位置更改文件中定义的路径,即Batch file 将硬编码路径更改为我想要的路径,batch-file,Batch File,我需要使用所需的路径位置更改文件中定义的路径,即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\
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设置为path
或者简单地说,找到并替换路径。. e、 g:-
'folderLocation'\\standalone\\uploads
就像智慧在每一条道路上飞扬。
在批处理脚本中可以吗?事实上,我在批处理脚本方面没有很好的知识
非常感谢您的帮助。这适用于您的示例数据,并使用一个名为
repl.bat
的助手批处理文件,该文件来自-
使用父路径方法
File currentPath=新文件(dir.getParent())
String currentFolder=currentPath.getName().toString()thanx。我必须在脚本中包含repl.bat脚本吗?或者它的任何其他解决方案?实际上,duster.properties文件位于C:\\progra~2\\Test\\Demo\\jboss7\\standalone\\uploads的位置,同样,我还有几个文件存在于不同的文件夹位置进行编辑。您可以将repl.bat放在路径上,它可以用于许多其他任务,或者与我在上面提供的批处理文件.yathanx。现在我已经将批处理文件repl.bat和myfile.bat放在同一个文件夹中。myfile.bat文件由上面的代码和我查找文件夹的代码组成。只需双击myfile.bat,就会出现错误“C:\Users\LilBird\Desktop\repl.bat(1,6)Microsoft JScript编译错误:条件编译已关闭”我想我的方法对您来说不是很清楚。我是否应该就我尝试过的所有代码和流程提出另一个问题?
@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"