Santiago
Santiago

Reputation: 131

Batch file to map a drive when the folder name contains spaces

I am trying to map a drive using a batch file. I have tried:

net use m: \\Server01\myfolder /USER:mynetwork\Administrator "Mypassword" /persistent:yes

It works fine. The problem comes when I try to map a folder with spaces on its name:

net use m: \\Server01\my folder /USER:mynetwork\Administrator "Mypassword" /persistent:yes

I have tried using quotes, using myfold~1 but nothing works.

An easy way would be renaming the folder but I have it mapped in more than 300 workstations so is not a very good idea.

Upvotes: 12

Views: 106294

Answers (5)

gkarasik
gkarasik

Reputation: 11

net use f: \\\VFServer"\HQ Publications" /persistent:yes

Note that the first quotation mark goes before the leading \ and the second goes after the end of the folder name.

Upvotes: 1

Stefn
Stefn

Reputation: 21

I'm not sure this will help you to much by I once needed a batch file to open a game, the .exe was in a folder with blanks (duh!) and I tried : START "C:\Fold 1\fold 2\game.exe" and START C:\Fold 1\fold 2\game.exe - None worked, then I tried

   START C:\"Fold 1"\"fold 2"\game.exe and it worked 

Hope it helps :)

Upvotes: 2

chalup
chalup

Reputation: 8516

I just created some directories, shared them and mapped using:

net use y: "\\mycomputername\folder with spaces"

So this solution gets "works on my machine" certificate. What error code do you get?

Upvotes: 15

ghostdog74
ghostdog74

Reputation: 342453

whenever you deal with spaces in filenames, use quotes

net use "m:\Server01\my folder" /USER:mynetwork\Administrator "Mypassword" /persistent:yes

Upvotes: 2

Axarydax
Axarydax

Reputation: 16603

net use "m:\Server01\my folder" /USER:mynetwork\Administrator "Mypassword" /persistent:yes 

does not work?

Upvotes: 1

Related Questions