How to read file contents into a variable in a batch file? -


This batch file launches live to test live. I want to add a check barrier to this file which ensures that a special release document has a special cific folder.

  "c: \ program files \ Windows resource kit \ tool \ robocopy.exe" "\\ testerver \ testapp $" "\\ lifeerver \ liveapp $" *. * / E / XA: H / PURGE / XO / XD ".svn" / NDL / NC / NS / NP del "\\ Live \ Liveapp $ \ web.config" ren "\\ lifeerver \ liveapp $ \ web.live .config "web.config  

So I have some questions about how to get it ....

  1. A version.txt file is in the \\ testerver \ testapp $ folder, and only content is the file build number (For example, 45 for 45 builds) How do I read the contents of the version.txt file in a variable in the batch file?

  2. I get a file, \\ fileserver \ myapp \ releaseocs \ {build} .doc , from 1 build instead of {build} Using the variable?

Read the contents of the file in one variable:

  for "/ f" delims = "%% x in (version.txt) Build = %% x  

or

  Set / P Build = & lt; Version.txt  

The file will work with the same line in both, for the variable the last will put the line in the variable, while set / p will use the first one.

Using variables - just like any other environment variable - this is one, after all:

 % Build%  

To check existence:

  if present \\ fileserver \ myapp \ releaseocs \% Build% .doc ...  

Although it may well be that there is no UNC path allowed there. It can not be tested now but keep this in mind.


Comments