改变的文件的路径位置到所需的路径 [英] Changing the path location of a file to the desired path

查看:175
本文介绍了改变的文件的路径位置到所需的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

欲替换定义成文件即logging.properties到jboss7位置的期望位置的路径的内容的路径。

I want to replace the content paths defined into the file i.e logging.properties to the desired location path of the jboss7 location .

基本上我使用安装在那里我有我的浏览文件夹jboss7并定位到用户的任何需要的位置。但在jboss7的一些文件有像在给定的logging.properties文件中定义了一些硬codeD路径。

Basically i'm using installer where i have to browse my jboss7 folder and locate it to any desired location of the user . But in few files of jboss7 there are some hardcoded path defined like in given logging.properties file.

我要硬codeD路径更改到所需的位置路径。

I need to change that hard coded path to the desired location path.

截至目前我遇到repl.bat,并在同一文件夹下的test.bat文件。

As of now i'm having repl.bat and file test.bat files in the same folder.

repl.bat帮助文件可在以下网址找到: -

repl.bat helper file could be find in following link:-

<一个href=\"http://www.dostips.com/forum/viewtopic.php?f=3&t=3855\">http://www.dostips.com/forum/viewtopic.php?f=3&t=3855

我刚才复制的code和repl.bat文件创建的。

I just copied the code and created repl.bat file.

test.bat的文件: -

test.bat file :-

 @ECHO OFF
 SETLOCAL
 SET "folder="
 FOR /r "C:\" %%a IN (tintin.txt) do IF EXIST "%%a" SET "folder=%%~dpa"&GOTO got1
 FOR /r "D:\" %%a IN (tintin.txt) do IF EXIST "%%a" SET "folder=%%~dpa"&GOTO got1
 :got1
 echo "%folder%"
 PAUSE

 set "newpath=%folder%"
 set "newpath=%newpath:\=\\%"
 echo "%newpath%"
 PAUSE
 type "logging.properties" | repl "(Directory=).*(\\\\standalone\\\\)" "$1%newpath%$2">"logging.properties.tmp"
 PAUSE
 move "logging.properties.tmp" "logging.properties"
 PAUSE
 GOTO :EOF
 PAUSE

下面这个文件下的test.bat,我在寻找一个文件tintin.txt文件,并设置路径到一个变量名文件夹。 tintin.txt文件只是内部jboss7.This的文件夹是由于一个以上的jboss7应用服务器的文件夹的可能性进入系统。
到现在我已经得到了路径即C:\\用户\\ Anuj \\桌面\\ jboss7 \\,并设置成变量文件夹。
现在有文件名为logging.properties到该文件夹​​的位置
C:\\用户\\ Anuj \\桌面\\ jboss7 \\独立\\配置

Here in this test.bat file , i'm searching a file tintin.txt file and setting the path into a variable name as 'folder'. tintin.txt file is just inside the folder of jboss7.This is because of the possibilities of more than one jboss7 application server folder into the system. Till now i have got the path i.e "C:\Users\Anuj\Desktop\jboss7\" and set into the variable 'folder'. Now there is file named logging.properties into the folder location C:\Users\Anuj\Desktop\jboss7\standalone\configuration

logging.properties: -

logging.properties :-

 com.latilla.import.uploadDirectory=C:\\progra~2\\Latilla\\C4i\\jboss7\\ standalone\\uploads
 com.latilla.import.maxFilesUploadNumber=10


com.latilla.export.templateFile=C:\\progra~2\\Latilla\\C4i\\jboss7\\standalone\\templates\\GDV_HDI_Format.xls
com.latilla.etl.pluginsRootDirectory=C:\\progra~2\\Latilla\\C4i\\jboss7\\standalone\\cloverETL\\plugins

 com.latilla.etl.templatesDirectory=C:\\progra~2\\Latilla\\C4i\\jboss7\\standalone\\etl

 com.latilla.db.user=postgres
 com.latilla.db.pass=password

repl.bat帮助文件帮助设置为变量名文件夹所需的路径即路径替换URL路径。
我想替换C:\\ PROGRA〜2 \\ Latilla \\ C4I \\ jboss7 \\设置为变量名文件夹的路径。
注意: -
在这里logging.properties文件路径内容是有路即Ç不同的格式:\\
是指双斜线。 \\

可能是我已经尝试test.bat的是不正确的脚本。
当我双击该文件下的test.bat我得到错误。

Might be the script that i have tried test.bat is incorrect. When i double click the test.bat file i got error.

推荐答案

虽然我不能帮你解决您正在使用的同时获得发行 repl.bat 文件,我可以建议解决路径替换最初的问题以不同的方式。

Although I can't help you with fixing the issue you are getting while using the repl.bat file, I can suggest a different way of solving the initial problem of path replacement.

如果在 jboss7 字符串保证是present在您的配置文件(S),你可以试试下面的办法所有的原始路径:

If the jboss7 string is guaranteed to be present in all the original paths in your configuration file(s), you could try the following approach:

@ECHO OFF
SETLOCAL DisableDelayedExpansion
FOR /F "delims=" %%A IN ('DIR /B /S C:\tintin.txt') DO (CD /D "%%~dpA" & CALL :got1)
FOR /F "delims=" %%A IN ('DIR /B /S D:\tintin.txt') DO (CD /D "%%~dpA" & CALL :got1)
GOTO :EOF

:got1
SET "propfile=%CD%\standalone\configuration\logging.properties"
IF NOT EXIST "%propfile%" GOTO :EOF
SET "tempfile=%TEMP%\logging.properties.tmp"
FIND /I /V "jboss7\\" >"%tempfile%"
>>"%tempfile%" (
  FOR /F "tokens=1,* delims=" %%I IN ('FIND /I "jboss7\\"') DO (
    SET "pathname=%%J"
    SETLOCAL EnableDelayedExpansion
    IF NOT "!pathname!" == "!pathname:*jboss7\\=!" (
      SET "pathname=%__CD__:\=\\%!pathname:*jboss7\\=!"
    )
    ECHO %%I=!pathname!
    ENDLOCAL
  )
)
ECHO Old file "%propfile%":
TYPE "%propfile%"
ECHO =======================================
ECHO New file:
TYPE "%tempfile%"
PAUSE
:: uncomment the next line once you have verified the replacement works correctly
::MOVE "%tempfile%" "%propfile%"

在搜索的 tintin.txt 文件已略有从而有可能使这一进程更快的改变。相反,遍历每个目录并检查它是否包含文件,环路现在读 DIR ,仅返回实际存在的条目的输出。

Searching for the tintin.txt file has been changed slightly so as to possibly make the process faster. Instead of iterating over every directory and checking if it contains the file, the loops now read the output of DIR, which returns only actually existing entries.

请注意,您也可以使用 FOR / R 循环,因为在你的present code,具有同样的效果,即只返回存在的路径,但IN子句需要包含一个面具,而不是一个普通的名字,但是这必须是一个面具在你的系统不仅仅是 tintin.txt 。举例来说,如果你知道肯定,有可能是没有名为 tintin.txt1 tintin.txtx 或任何文件别的地方 tintin.txt 后面跟着一个字符,你可以使用下面的模板,而不是:

Note that you could also use a FOR /R loop, as in your present code, with the same effect i.e. returning only existing paths, but the IN clause would need to contain a mask rather than a normal name, but that would have to be a mask that couldn't match anything else in your system than just tintin.txt. For instance, if you knew for certain that there could be no file called tintin.txt1 or tintin.txtx or anything else where tintin.txt is followed by exactly one character, you could use the following template instead:

FOR /R "C:\" %%A IN (tintin.txt?) DO (CD /D "%%~dpA" & CALL :got1)

和同为 D:\\ 。这将只返回引用文件实际存在和匹配面膜。

and same for D:\. That would return only references to files actually existing and matching the mask.

此外,您还可以看到,循环不跳( GOTO )的 GOT1 标签,而是呼叫的的 GOT1 子程序。随着这种变化,有可能在一气呵成处理多个应用程序实例。我不知道你可以安装多次。如果没有,你可能会想改回 GOTO

Also, you can see that the loops do not jump (GOTO) to the got1 label but instead call the got1 subroutine. With that change, it is possible to process many application instances in one go. I don't know yours can be installed multiple times. If not, you'll probably want to change it back to GOTO.

在我的脚本中的子程序被引用作为你描述中指定使用其完整路径的配置文件( ... \\独立\\配置\\ logging.properties )。出于某种原因,在脚本文件只是由其名称引用,即使没有preceding CD或PUSHD命令改变当前目录到文件的位置。我以为你是试图简化你的脚本,并省略了一点,不管是有意还是不行。否则,我可能已经错过了你的解释和/或脚本什么的。

The subroutine in my script is referencing the config file using its full path as specified in your description (...\standalone\configuration\logging.properties). For some reason, in your script the file is referenced simply by its name, even though there's no preceding CD or PUSHD command changing the current directory to the location of the file. I assumed you were trying to simplify your script and omitted that bit, whether intentionally or not. Otherwise I may have missed something in your explanation and/or script.

验证该配置文件存在于预期的位置后,将替换本身以这种方式完成的:

After verifying that the config file exists at the expected location, the replacement itself is done in this way:


  1. 所有非路径配置线被写入临时文件一气呵成。

  1. All the non-path config lines are written to a temporary file with one go.

含有一个路径中的每个配置行以这种方式处理:

Every config line containing a path is processed in this way:


  • 如果它不包含 jboss7 \\\\ 字符串,它被省略;

否则路径直至并包括部分 jboss7 \\\\ 被删除;

otherwise the part of the path up to and including jboss7\\ is removed;

在当前目录中的剩余部分之前插入(后每 \\ 替换 \\\\ );

the current directory is inserted before the remaining part (after every \ is replaced with \\);

在新值放回配置行;

更​​新行被添加到相同的临时文件

the update line is added to the same temporary file.

旧版本与替换为新的配置文件。

The old version is of the configuration file replaced with the new one.

显然,该脚本可以更改处理的文件行的顺序,但它假定的无所谓。

Obviously, the script may change the order of lines in the processed file, but it is assumed that that doesn't matter.

这篇关于改变的文件的路径位置到所需的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆