0

I have a .bat file on windows, which i want to be able to copy to any new folder and doubleclick to start a http server. It only contains one line which is:

http-server %~dp0

The %~dp0picks up the full path to whatever directory the .bat file is currently in. Credit to this answer for that.

It works well when none of the folders in the file path contain a space.

How can i modify the batch file to account for situations where some directories in the path contain a space in the name?

cheers

PS: Im new to this :)

Community
  • 1
  • 1
Nick
  • 3,454
  • 6
  • 33
  • 56
  • thats what quotes were made for – Jaromanda X Mar 03 '17 at 08:12
  • or you could point me in the right direction..... – Nick Mar 03 '17 at 14:20
  • `http-server "%~dp0"` – Jaromanda X Mar 04 '17 at 01:49
  • Hi, thanks, i tried that but when i try to connect to localhost from the browser i get the error "This site can’t be reached". I tried adding /index.html after the word local host with the same result. The good thing now however is i can see the entire path to the website folder on the commandline screen. Do i need to add something else? cheers – Nick Mar 06 '17 at 08:16

1 Answers1

1

It turns out removing the %~dp0 and just having http-server and nothing else in the batch file makes it work!

It then serves up whatever is in the current directory as shown:

enter image description here

Nick
  • 3,454
  • 6
  • 33
  • 56