11

Today I saw again a question where the problem was OP didn't know he needs to escape the backslashes in a filename that was hard-coded in the source code. It usually boils down to this:

const char *fileName = "c:\unescaped\backslashes.txt";

Do I have green light to make such a post, akin to What is an undefined reference/unresolved external symbol error and how do I fix it?


Also any suggestions for its title/body? Right now I'm thinking this:

Title:

Why do I have to use double backslashes for file paths in code?

Body:

In languages like C, C++, Java, Python, and others, why do I need to use double backslashes when hard-coding a file path?


Also could it be made language-agnostic, as a lot of unrelated languages have this and it would be applicable to them.

It would be best if a moderator can make it a community wiki question, but if not, I or someone else can just ask and answer it.

12
  • 8
    "My backslashes are not working"
    – BoltClock
    Feb 4, 2015 at 16:09
  • 2
    @BoltClock: I'm not quite sure whether that's parody, cynicism or simply acute observation. Still, that title seems canonical. Feb 4, 2015 at 16:34
  • If you want the post to be CW, just post it and flag it to be marked as CW.
    – Servy
    Feb 4, 2015 at 16:44
  • @Servy Can't do that for questions, though. The checkbox is available only for answers.
    – sashoalm
    Feb 4, 2015 at 16:45
  • @sashoalm You can't mark it as CW yourself. You can flag the question for moderator attention and ask the mod to mark the post as CW, and if it's appropriate they will. You don't need to ask a mod to ask the actual question first.
    – Servy
    Feb 4, 2015 at 16:51
  • @Servy Ok, but I'll wait for an answer here at least saying if it's appropriate to ask this question or not. Last time I tried to ask a question there came someone downvoting it and arguing with me saying I was posting it just to earn rep. Some people are concerned about that it seems.
    – sashoalm
    Feb 4, 2015 at 16:52
  • @sashoalm In case you need a checklist, I've created one in an answer of mine
    – rene
    Feb 4, 2015 at 16:55
  • @sashoalm When you post any question it needs to be a quality question that meets all of the site's quality standards. If you are self-answering a question and that question would not have been a quality question if you saw someone actually ask it (without an answer) in earnest, expecting a response, then you shouldn't expect the response to be any different just because you posted an answer. It has to do with the quality of the actual question.
    – Servy
    Feb 4, 2015 at 16:56
  • 5
    This has my vote. Any time you see a question get repeated over and over again, it's fodder for a canonical post. Feb 4, 2015 at 17:25
  • 1
    @RobertHarvey I posted it! If you have moderator powers, can you mark it community-wiki? stackoverflow.com/questions/28328052/…
    – sashoalm
    Feb 4, 2015 at 17:55
  • @rene I posted it - stackoverflow.com/questions/28328052/…. I followed the regex question as template. Thanks for the advice.
    – sashoalm
    Feb 4, 2015 at 17:56
  • sashoalm: the canonical title should indeed have been "Why aren't my backslashes working?" not "Why do I have to use double backslashes...?" because you don't to use double backslashes: a) Windows has been accepting forward-slashes since 1995 and b) in Python, you don't have to use double backslashes, you can (and should) use raw-strings: r'c:\unescaped\backslashes.txt'
    – smci
    Sep 13, 2018 at 3:35

1 Answer 1

1

After a few thumbs up I posted the question here - Why do I have to use double backslashes for file-paths in code?.

I followed this question as a template - Reference - What does this regex mean?

I've notified the moderators, hopefully it will be marked as community-wiki soon. I've posted a preliminary answer and I'll leave further improvements to the community.

Search query for finding duplicate questions

Unfortunately there is no good way to find duplicates. I've made a search query that searches for the phrase "double backslashes" and "filename" in the answers:

https://stackoverflow.com/search?q=%22double+backslashes%22+filename+is%3Aanswer

This is the best I could come up with.

9
  • 3
    I think the question should really be more like a question a user might ask, to increase the chance they realize it applies to them. You can talk about its canonicity at the end of the question, possibly in smaller font. Feb 4, 2015 at 17:57
  • @JeffreyBosboom I'll further edits to the community. Hopefully the question will be marked as community-wiki soon. I don't plan on editing it any more myself, however.
    – sashoalm
    Feb 4, 2015 at 17:58
  • 1
    It would be easier for people asking this question to find if the title sounded more like "Why doesn't my file path work" or something along those lines. Look at the duplicate questions being posted and maybe try to modify it to something similar. Do these users usually recognize that the backslashes are the problem? If not, this will be hard to Google.
    – eddie_cat
    Feb 4, 2015 at 18:00
  • 2
    google.com/… for zillions of C# dupes
    – eddie_cat
    Feb 4, 2015 at 18:07
  • @eddie_cat I found this - stackoverflow.com/questions/1302864/…. I wonder if it could be marked as duplicate? It's highly upvoted, and seems to be a canonical question itself, albeit for C# only.
    – sashoalm
    Feb 4, 2015 at 18:16
  • Would it make sense to include the language-specific thing where C# lets you use @"text" to disable expanding escape sequences (called "verbatim string literals")?
    – Pokechu22
    Feb 4, 2015 at 18:17
  • 1
    @Pokechu22 You mean in the answer? Sure, you can edit it if you want.
    – sashoalm
    Feb 4, 2015 at 18:18
  • 1
    @eddie_cat I think getting a good population of duplicates will solve that problem. The duplicates will be phrased how the new users think of it in their mind, and the root duplicate will describe the problem they way they SHOULD think of it. Feb 4, 2015 at 22:33
  • @JasonMArcher That's what I was thinking, too, doesn't Google take into account the text of links pointing to a link?
    – sashoalm
    Feb 5, 2015 at 9:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .