Change file path location to desired path

I want to replace the content paths defined in ie logging.properties file with the desired jboss7 location path.

I mainly use the installer, where I need to browse the jboss7 folder and find it anywhere in the user. But in several jboss7 files there is a specific hardcoded path, defined as in this logging.properties file.

I need to change this hard-coded path to the desired path.

Currently, I have repl.bat files and test.bat file in the same folder.

The repl.bat helper file can be found at the following link: -

http://www.dostips.com/forum/viewtopic.php?f=3&t=3855

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

file test.bat: -

@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 

Here, in this test.bat file, I search for the file tintin.txt file and set the path to the variable name as "folder". The tintin.txt file is located only in the jboss7 folder. This is due to the capabilities of more than one jboss7 application server folder on the system. So far, I have the path ie "C: \ Users \ Anuj \ Desktop \ jboss7 \" and set to the "variable" folder. Now in the folder is a file called logging.properties C: \ Users \ Anuj \ Desktop \ jboss7 \ offline \ configuration

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 

The repl.bat helper file helps replace the URL with the desired path. ie the path is set to the variable names folder. I want to replace C: \ progra ~ 2 \ Latilla \ C4i \ jboss7 \ with the start installed in the variable names folder. Note: - here in logging.properties the contents of the path file have a different path format ie C: \ means double forward slash. \

Maybe the script I tried test.bat is incorrect. When I double-clicked the test.bat file, I got an error.

+8
batch-file
source share
1 answer

Although I cannot help you solve the problem that occurs when using the repl.bat file, I can offer another way to solve the original problem of replacing the path.

If the jboss7 line jboss7 guaranteed to be present in all source paths in your configuration files, you can try the following approach:

 @ECHO OFF SETLOCAL DisableDelayedExpansion FOR /F "delims=" %%A IN ('DIR /B /SC:\tintin.txt') DO (CD /D "%%~dpA" & CALL :got1) FOR /F "delims=" %%A IN ('DIR /B /SD:\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%" 

The search for the tintin.txt file tintin.txt been slightly modified to speed up the process. Instead of iterating over all directories and checking to see if it contains a file, the loops now read the DIR output, which returns only existing entries.

Please note that you can also use the FOR /R loop, as in your current code, with the same effect, i.e. return only existing paths, but only the mask should be specified in the IN clause, not the usual name, but it should be a mask that cannot match anything else on your system than just tintin.txt . For example, if you knew for sure that there could not be a file named tintin.txt1 or tintin.txtx or anything else where exactly one character follows tintin.txt , you can use the following pattern instead:

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

as well as for D:\ . This will only return links to actually existing files and the corresponding mask.

In addition, you can see that the loops do not jump ( GOTO ) to the got1 label, but instead call the got1 subroutine. With this change, you can process multiple application instances at a time. I do not know that yours can be installed several times. If not, you probably want to change it to GOTO .

The subroutine in my script references the configuration file using the full path specified in your description ( ...\standalone\configuration\logging.properties ). For some reason, in your script, the file is referenced simply by its name, even if there is no previous CD or PUSHD command that changes the current directory to the file location. I suggested that you try to simplify your script and miss this bit, intentionally or not. Otherwise, I might have missed something in your explanation and / or script.

After verifying that the configuration file exists in the expected location, the replacement itself is performed as follows:

  • All configuration lines without a path are written to a temporary file at a time.

  • Each configuration line containing a path is processed as follows:

    • if it does not contain the string jboss7\\ , it is omitted;

    • otherwise, part of the path to and including jboss7\\ ;

    • the current directory is inserted before the rest (after replacing each \ with \\ );

    • the new value is returned to the configuration line;

    • The update line is added to the same temporary file.

  • In the old version, the configuration file is replaced with a new one.

Obviously, the script can reorder the lines in the processed file, but it is assumed that it does not matter.

+3
source share

All Articles