2

Is there any way to replace a space in %username% with an underscore. Within cmd.

For example:

Username: john doe

Actual Folder path for %username%: john_doe

    NET USE Z: \\server\folder\%username%\ /P:Yes
Cody Gray
  • 230,875
  • 49
  • 477
  • 553
Cerebus
  • 21
  • 3
  • http://stackoverflow.com/questions/2772456/string-replacement-in-batch-file – Cody Gray Nov 30 '16 at 00:45
  • 4
    State `NET USE Z: "\\server\folder\%username%" /PERSISTENT:Yes` instead, so you can use directory names with spaces in them... – aschipfl Nov 30 '16 at 01:45

1 Answers1

3
set "newusername=%username: =_%"

creates a new variable with the space replaced.

Magoo
  • 72,034
  • 7
  • 58
  • 78