Using Net Share with Folders Containing a Space in the Name

Recently I was writing a batch file for setting up network shares. I had no problem finding examples. However, though I saw many examples of how to set up the net share command, all were basic and didn't illustrate how to do so for folders or drives that had a space in the name.

So let's show you what I eventually found out.

First, the syntax for Net Share:

NET SHARE sharename=drive:path /REMARK:"My shared folder" [/CACHE:Manual | Automatic | No ]

Here's an example:

NET SHARE SharedFolder=c:\Documents /REMARK:"Docs on server ABC"

This is akin to most of the examples I found; it doesn't depict a space. Finally after some persistent searching, I stumbled upon a page that did. At Maxi-pedia's Net Share page, I found the following:

"In case your folder or server name contains a space, you need to enclose the drive and the path of the directory in quotation marks (for example, "C:\MySharedFolder"). Not providing quotation marks results in an error message: System error 85 has occurred."

So this will work:

NET SHARE "Shared Folder"="c:\Shared Folder" /REMARK:"Docs on server ABC"

You must put quotes around the share name AND the path if both have a space in the name, like My Documents, for example.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.