# Solved: how to read a .properties file from batch



## potchi (May 12, 2011)

I have a properties file (myFile.properties) that contains the line
...
myPath=
myProfile=
...

those lines serves as a parameter, and I want to get those parameter and pass it 
to my batch file (potchi.bat)

is that possible??

Thanks!


----------



## Squashman (Apr 4, 2003)

Should be something like this. Didn't test this. Just going off the top of my head.


```
For /F "tokens=1* delims==" %%A IN (myFile.properties) DO (
	IF "%%A"=="myPath" set myPath=%%B
	IF "%%A"=="myProfile" set myProfile=%%B 
	)
call potchi.bat "%myPath%" "%myProfile%"
```


----------



## potchi (May 12, 2011)

Hi, just a few questions
- is this code written in potchi.bat? or it should be in another batch file (potchi1.bat)
- is it required that myFile.properties and potchi.bat be on the same directory?

For this problem here's my set-up
- myFile.properties is located in D:\myDirectory\etc
- potchi.bat is located in D:\myDirectory\bin

and all my batch file should be in D:\myDirectory\bin 


I tried this code, save it in potchi.bat and it gives me

D:\myDirectory\bin>potchi
The syntax of the command is incorrect.

D:\myDirectory\bin>For /F "tokens=1* delims==" %A IN (myFile.properties)

and actually 
myFile contains '.' in it

myFile is actually my.File.properties and
myProfile is my.websphere.profile
myPath is my.websphere.directory

Thanks!!!


----------



## potchi (May 12, 2011)

Hi, just a few questions
- is this code written in potchi.bat? or it should be in another batch file (potchi1.bat)
- is it required that myFile.properties and potchi.bat be on the same directory?

For this problem here's my set-up
- myFile.properties is located in D:\myDirectory\etc
- potchi.bat is located in D:\myDirectory\bin

and all my batch file should be in D:\myDirectory\bin 


I tried this code, save it in potchi.bat and it gives me

D:\myDirectory\bin>potchi
The syntax of the command is incorrect.

D:\myDirectory\bin>For /F "tokens=1* delims==" %A IN (myFile.properties)

and actually 
myFile contains '.' in it

myFile is actually my.File.properties and
myProfile is my.websphere.profile
myPath is my.websphere.directory

Thanks!!!


----------



## potchi (May 12, 2011)

Im sorry my mistake, I typed it wrong, so my next question is

how to catch the %myProfile and %myPath in potchi.bat??

in my potchi.bat I write

echo "%myProfile"
echo "%myPath"

but it did not print the values I want.


----------



## potchi (May 12, 2011)

Thank you so much for this code I solved my problem...


----------



## Squashman (Apr 4, 2003)

If you solved your problem then post your final code so that everyone knows what the solution was and then use the Thread Tools link at the top of your first post to mark your Thread Solved.


----------



## potchi (May 12, 2011)

For /F "tokens=1* delims==" %%A IN (myFile.properties) DO ( IF "%%A"=="myPath" set myPath=%%B IF "%%A"=="myProfile" set myProfile=%%B ) call potchi.bat "%myPath%" "%myProfile%" 

This code is the solution to my problem! 
Thanks squashman!


----------

