I have a batch file that will read values from a .ini file line by line, and use these variables to do other steps.
config.ini
Folder=Z:\task\first task\archive\
FileName=aFileName.xlsx
break
Then in my batch file i read the lines like the following and copy it to somewhere else like the following: job.bat
for /f "tokens=1,2 delims==" %%a in (.\config.ini) do (
if %%a==Folder set Folder=%%b
if %%a==Format set Format=%%b
if %%a==break (
call :copyFile
)
)
GOTO :EOF
:copyFile
xcopy %Folder%%Filename% D:\abc\ /f /y
GOTO :EOF
so the problem is at %Folder%%Filename% for some reason, there is a space between the folder path and File name so it turns out to be
Z:\task\first task\archive\ aFileName.xlsx
I have tried to echo the variable after reading from file line by line and do echo "%Folder%"
and i can see there are white space at the end of the variable. is there anyways to trim ONLY the end of the variable? I have tried some suggestions online, but it seems like it would also remove the white space within the variable, as you can see I do have a white space in the folder variable
Also, is there a way to exclude some of the charaters during string replacement. eg:
set filename=name_mm.txt
call set replaceName=%filename:mm=01%
this will replace the character mm to 01 in result of name_01.txt but in another case, i got a filename that also have mm inside eg:
set filename=communicate_mm.txt
in this case, is there a way to ONLY replace the mm add the end? I know i could've replace the string _mm instead of mm, but there are other cases that the file name format like yyyymmdd.