dexter
dexter

Reputation: 7203

Create a folder inside existing subfolder in batch file

Should be pretty easy right.. I am battling this. Or rather it battles me. So I do:

     net use w: /delete


     SET SERVER1=myserver
     SET ROOT_DRIVE=c$

     SET WEB_ROOT=\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\
     SET DESTINATION_FOLDER=PPA20_TEST


     net use w: \\%SERVER1%\%ROOT_DRIVE% /User:%usern% %password%  /persistent:yes 
     cd w:%WEB_ROOT%
     md %DESTINATION_FOLDER%

So supposedly this should create my DESTINATION_FOLDER inside WEB_ROOT folder under the mapped drive. Instead it creates it where that batch file is called from..

Upvotes: 1

Views: 1653

Answers (2)

Andriy M
Andriy M

Reputation: 77657

It's because it doesn't change the active drive, it merely changes the active directory on the drive W:.

To change both the active drive and the active directory, use the /D switch:

cd /d w:%WEB_ROOT%

However, you may not really need to set the w:%WEB_ROOT% directory active. Just specify the full path in the md command:

md w:%WEB_ROOT%%DESTINATION_FOLDER%

Upvotes: 1

Just add w: before your cd w:%WEB_ROOT% call, so it would be like this:

w:
cd w:%WEB_ROOT%
md %DESTINATION_FOLDER%

So you first change to drive w: to then change directory on it.

Upvotes: 2

Related Questions