2

I have a web application created in Visual Studio 2013. I have this appSetting in my Web.Config file:

<add key="cloudVersion" value="@@NEW@@"/>

After I publish the application, I run a bat file that copies the published directory, appends today's date to the directory name, compresses the updated directory, and uploads it to Google drive so the rest of my team can access it.

I am attempting to use the same bat file to modify the cloudVersion setting so we can see when it was published from within the application. I have this code:

@echo off &setlocal
set "search=@@NEW@@"
set "replace=%yy%%mm%%dd%"
(for /f "delims=" %%i in ('findstr /n "^" "%""C:\original files\Web.config""%"') do (
    set "line=%%i"
    setlocal enabledelayedexpansion
    set "line=!line:%search%=%replace%!"
    echo(!line!
    endlocal
))>"%""C:\Publish Folder\CLOUD"%yy%.%mm%.%dd%"\Web.Config""%"
type "%""C:\Publish Folder\CLOUD"%yy%.%mm%.%dd%"\Web.Config""%"

It correctly copies the Web.Config file and replaces the cloudVersion variable value. However, the whole file now has each line numbered like this:

23:  </system.web.extensions>
24:  <appSettings>
25:    <add key="cloudVersion" value="20140818"/>

How do I use the bat to update the value, but not get numbered lines that I have to later delete?

davids
  • 5,397
  • 12
  • 57
  • 94
  • 1
    `/n ` explicitly asks for line numbers, remove it. – Alex K. Aug 18 '14 at 14:55
  • @AlexK. I figured it would be easy, this is just my first experience with bat files. That worked, thanks! If you put it as an answer, I will accept it. – davids Aug 18 '14 at 15:13

1 Answers1

2

In case anyone is looking, here is what I did:

@echo off &setlocal
set "search=@@NEW@@"
set "replace=%yy%%mm%%dd%"
(for /f "delims=" %%i in ('findstr "^" "%""C:\original files\Web.config""%"') do (
    set "line=%%i"
    setlocal enabledelayedexpansion
    set "line=!line:%search%=%replace%!"
    echo(!line!
    endlocal
))>"%""C:\Publish Folder\CLOUD"%yy%.%mm%.%dd%"\Web.Config""%"
type "%""C:\Publish Folder\CLOUD"%yy%.%mm%.%dd%"\Web.Config""%"
davids
  • 5,397
  • 12
  • 57
  • 94