4
I am automating some processes on a Windows server, and would like to create some files. bat for this but for such would be necessary the . BAT were able to read a configuration file so I did the following:
get bat file.:
@echo off
setlocal
@if not exist "%1" (
echo Config file not found in "%1"
exit /B
)
@for /f "tokens=1,2 delims= " %%A in (%1) do (
set %%A=%%B
)
echo %folder%
and created a configuration file called winscp.conf with the following data:
folder %appData%\winscp
version 5.7.4
visit http://sourceforge.net/projects/winscp/files/WinSCP/
download http://sourceforge.net/projects/winscp/files/WinSCP/5.7.4/winscp574.zip
and then I call the . bat so:
get winscp.conf
So far everything well the variable is read and created exactly as I would like, however this in the use of environment variables, I would like app data was interpreted and stored in the variable but instead of having something like this
C:\Users\root\AppData\Roaming\winscp
I get it:
%appData%\winscp
In short: I would like the %appData% to be interpreted but instead I am getting the literal value.
Anyone can help?
Very clever, huh. Ever thought of using that creativity with the Powershell? It is much more powerful and simpler. Now my question: what is the problem in getting
%appData%\winscp
value of the variable since this is a valid path for you to read and write files along the script?– Caffé
The problem is that if I try to run something like mkdir %Folder% instead of creating the folder using the path of the environment variable it creates a folder relative to .bat. it creates a folder named %appData%. I’m thinking about doing this with Cli PHP or Nodejs, I thought it would be simpler with a file. bat
– Daniel de Andrade Varela
It has VBS option, too. The advantage of . BAT, Powershell and VBS is that they are native to Windows, do not need any additional tool to run. Anyway it’s weird. I tested it now
set teste=%appdata%\teste
followed bymkdir %teste%
and the folder has been created correctlyC:\Users\Caffé\AppData\Roaming\teste
.– Caffé
Yes it creates normally if I’ve been in the same file. bat, the problem is when I search the file. conf, if you can and will, try to recreate my password with the file . bat and the file . conf.
– Daniel de Andrade Varela
Really curious... I answered the question in Soen. http://stackoverflow.com/questions/31592509/how-to-set-a-variable-with-an-environment-variable-read-from-a-text-file Follow there.
– Caffé
Problem solved in Soen :-) Updated answer.
– Caffé