Spaces in a file path

Started by
3 comments, last by smart_idiot 19 years, 5 months ago
I have a line of code as such: system("edit C:\\My Documents\\test.txt"); The problem is, it doesn't see the space. How do I get it to use the space between My and Documents?
Advertisement
well, normally at the command line you could wrap the entire path in quotes, but since you're already inside a string literal, try

system("edit \"C:\\My Documents\\test.txt\"");

if that doesn't work, try escaping the space with '\ ' (not sure if that will work, either)

It's been a long time since I've seen a DOS or Win32 box and/or made system calls on it, but I'm pretty sure the first solution I suggested should work.
Greenspun's Tenth Rule of Programming: "Any sufficiently complicated C or Fortran program contains an ad-hoc, informally-specified bug-ridden slow implementation of half of Common Lisp."
DOS has a 8.3 limit on name lengths, so I think something like "C:\MY DOC~1\TEST.TXT" should work (cant quite remember though). This is because DOS truncates longer dir names to an 8 charater length (the .3 is for file extensions) and adds ~1 (or ~2, ~3 if theres more than one with the same first 6 characters).

Hope that helps, sorry if it doesnt (or is a load of BS).
Quote:Original post by BosskIn Soviet Russia, you STFU WITH THOSE LAME JOKES!
Quote:Original post by grekster
DOS has a 8.3 limit on name lengths, so I think something like "C:\MY DOC~1\TEST.TXT" should work (cant quite remember though). This is because DOS truncates longer dir names to an 8 charater length (the .3 is for file extensions) and adds ~1 (or ~2, ~3 if theres more than one with the same first 6 characters).

Hope that helps, sorry if it doesnt (or is a load of BS).


it's all good stuff. the older versions of dos limited file and folder names to 8 chars and no spaces.

so

c:\my documents
could be accessed as
c:\mydocu~1


...oh the nostalgia
Try

system("edit C:\\My\\ Documents\\test.txt");

or

system("edit \"C:\\My Documents\\test.txt\"");
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.

This topic is closed to new replies.

Advertisement