Discussion:
fopen() of Windows file names containing spaces
(too old to reply)
AileenRose
2006-12-09 16:53:43 UTC
Permalink
Please help! I have a very frustrating problem which makes me feel dumb
since I am a newbie at this.

The script needs to open a file and remove a line based on a fed value.
Basically it is a web button that calls:

removeline?c:/Program Files/user1/file.txt,line_that_will_be_removed

I take the argument before the comma separator and change the forward
slashes to back slashes.

I have gotten this to work from the command line in cygwin, modified it
to work from the command line in a cmd window. Now, I have to make it
work as the executable that is called from a web page.

I have tried double backslashing, but it cannot open the file.
My file value is something like:

C:\\Program Files\\user1\\file.txt

When I look at my apache logs it shows the error of :
Cannot open file: C:\\Program%20\\user1\\file.txt

Should I be taking care of the '%20' or is this just coming from the
fprintf? How can I "scrub' the filename so that it works from the web?

Thanks!
Ulrich Eckhardt
2006-12-09 17:21:05 UTC
Permalink
Post by AileenRose
I have tried double backslashing, but it cannot open the file.
C:\\Program Files\\user1\\file.txt
Cannot open file: C:\\Program%20\\user1\\file.txt
Okay, something's not quite right. The %20 is the way that spaces are
encoded in arguments passed to a webpage, I think. However, that doesn't
account for the disappearance of the 'Files' part of the name.
Post by AileenRose
Should I be taking care of the '%20' or is this just coming from the
fprintf?
No, definitely not.
Post by AileenRose
How can I "scrub' the filename so that it works from the web?
Dunno, first thing to find out is what exactly is going where. So I'd
suggest dumping the content of argc/argv to some logfile, possibly even in
binary. Also, find out if and how the webserver separates the arguments. I
guess that when you pass the filename to the webserver, a space is encoded
as a %20, so probably the webserver will pass this on just like that. In
your program, you then need to take that string and transform it back.
Talk to the Apache people, I'm sure they know better about these things
and will also possibly be able to counsel you on similar things you will
find.

What does all this have to do with GCC, btw?

Uli
--
http://gcc.gnu.org/faq.html
AileenRose
2006-12-09 17:30:08 UTC
Permalink
Thanks for your quick reply.
Post by Ulrich Eckhardt
What does all this have to do with GCC, btw?
The code is in c++ and I am rusty with managing string functions.

So I am dunno as to what string function will substitute '%20' in the
the filename?
AileenRose
2006-12-09 17:40:19 UTC
Permalink
Post by AileenRose
Thanks for your quick reply.
Post by Ulrich Eckhardt
What does all this have to do with GCC, btw?
The code is in c++ and I am rusty with managing string functions.
So I am dunno as to what string function will substitute '%20' in the
the filename?
Also, there is no 'replace' in my string.h. I tried using the
pcrecpp.h to get for globalreplace but abandon it since I was getting
errors compiling it.

btw, I am on a Windows Server 2003 system.
AileenRose
2006-12-09 17:42:28 UTC
Permalink
Post by AileenRose
Thanks for your quick reply.
Post by Ulrich Eckhardt
What does all this have to do with GCC, btw?
The code is in c++ and I am rusty with managing string functions.
So I am dunno as to what string function will substitute '%20' in the
the filename?
Also, there is no 'replace' in my string.h. I tried using the
pcrecpp.h to get for globalreplace but abandon it since I was getting
errors compiling it.

btw, I am on a Windows Server 2003 system.
AileenRose
2006-12-09 17:37:07 UTC
Permalink
Thanks for your quick reply.
Post by Ulrich Eckhardt
What does all this have to do with GCC, btw?
The code is in c++ and I am rusty with managing string functions.

So I am dunno as to what string function will substitute '%20' in the
the filename?
Ulrich Eckhardt
2006-12-09 18:01:17 UTC
Permalink
Post by AileenRose
Post by Ulrich Eckhardt
What does all this have to do with GCC, btw?
The code is in c++
1. This group discusses the C compiler of the GCC.
2. The GCC mostly only provides standard functions, anything else is in
external libraries.
3. I saw your similar posting on gnu.g++.help. Don't multipost please (look
up that term on google).
Post by AileenRose
and I am rusty with managing string functions.
strstr() might do the job of finding instances of %20, you can then replace
that and move the rest of the string further up front. However, spaces
aren't the only thing that is escaped, beware! The percent sign is
escaped, too, and possibly further things.
Post by AileenRose
So I am dunno as to what string function will substitute
'%20' in the the filename?
There is no such function in the C or C++ standardlibraries.

Uli
--
http://gcc.gnu.org/faq.html
René Berber
2006-12-10 03:56:01 UTC
Permalink
[snip]
Post by AileenRose
The script needs to open a file and remove a line based on a fed value.
removeline?c:/Program Files/user1/file.txt,line_that_will_be_removed
I take the argument before the comma separator and change the forward
slashes to back slashes.
I have gotten this to work from the command line in cygwin, modified it
to work from the command line in a cmd window. Now, I have to make it
work as the executable that is called from a web page.
I have tried double backslashing, but it cannot open the file.
C:\\Program Files\\user1\\file.txt
Which is wrong.

Are you using a script or a program?

If it is a program that uses fopen (as the title says) you have to
convert the path into a Cygwin path, meaning for the above:

/cygdrive/c/Program\ Files/user1/file.txt

which on the shell is done automagically sometimes, or using the
command `cygpath -w ...`

The important thing here is what is the script/program expecting, if it
is a program compiled under Cygwin it expects a path like the one I
showed, the same goes for Cygwin's bash, perl, etc.
Post by AileenRose
Cannot open file: C:\\Program%20\\user1\\file.txt
Should I be taking care of the '%20' or is this just coming from the
fprintf? How can I "scrub' the filename so that it works from the web?
No, the %20 is how Apache (or other web server) translated to html what
it could. If you use that notation with fopen() it will never work.
--
René Berber
Loading...