[batch-file] 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.

This question is related to batch-file

The answer is


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

does not work?


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 :)


whenever you deal with spaces in filenames, use quotes

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

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.