That won't work because if you double click the bat file in a \\unc share
then you get that error saying the UNC paths are not supported. It then
defaults to the Windows directory, so %cd% would be c:\windows in my case.

I ended up going with this:

@set uncpath=%0:\Dev.deployWeb.bat=%
@pushd %uncpath%
...

where the first line does a remove of the bat file's name from the %0
(which is the name of the original call including the full path name... )
so strip off the known bat file name and I've got the path. Pushd then does
the rest.


On Wed, Aug 21, 2013 at 10:35 AM, Preet Sangha <[email protected]>wrote:

> http://stackoverflow.com/questions/3848597/bat-current-folder-name
>
> set startdir=%cd%
>
> echo %startdir% is my current directory
>
>
>
> On 21 August 2013 13:37, Stephen Price <[email protected]> wrote:
>
>> Hey all,
>>
>> I have a batch file that deploys to the required environment and i'm
>> setting it up to output the deploy script into a folder as part of the
>> build on TFS.
>> Part of the batch file maps a drive using pushd and then the current path
>> of the drop. This changes with each build and contains the build version in
>> the path.
>>
>> I'm trying to work out how to dynamically update this batch file using
>> our current build process... we are transforming a parameters.xml file as
>> well as some app.config file for a windows service and I'm wondering if
>> it's possible to do a transform on a .bat file. (or even a .txt file I can
>> rename at the last step or something). So far I've not found anything
>> indicating if its possible.
>>
>> I may have to just add the registry that allows you to run cmd.exe from
>> \\unc paths (current get an error telling me its not supported but I know I
>> can change that).
>> That will be my workaround if I can't work out how to insert the path the
>> .bat file is run from. Or come up with some fancy .bat file tomfoolery to
>> work out the path it was run from (and pushd that path).
>>
>> CMD.EXE was started with the above path as the current directory.
>> UNC paths are not supported.  Defaulting to Windows directory.
>>
>> Hmm.. actually I might be able to do some string manipulation from the %0
>> to get the path... ahhhh this takes me back. Used to love working with .bat
>> files back in my infrastructure days. hehe
>>
>
>
>
> --
> regards,
> Preet, Overlooking the Ocean, Auckland
>

Reply via email to