Page 1 of 2

### Spaces in paths & filenames

Posted: Sat Jun 24, 2017 3:10 am UTC
Just this. Had a bit of a tiff break out on Reddit recently in a thread about hyphens vs. underscores regarding which inferior substitute was superior instead of just using spaces between the words in the name of a file or folder. (Hyphens, obviously, but this is quite beside the point.)

I don't find it at all difficult to enclose paths in single quotes when I happen to be using CLI. I do like when my filesystem looks like names for things instead of weird and unsightly coding conventions. I do find it frustrating when a script or application manages to fail to correctly treat a path as a string and fails in case of spaces, but that's a problem with the script, not the convention.

### Re: Spaces in paths & filenames

Posted: Sat Jun 24, 2017 3:41 am UTC
If it looks like the end of a token, it should be the end of a token.

Jose

### Re: Spaces in paths & filenames

Posted: Sat Jun 24, 2017 6:16 am UTC
Spoiler:
By habit, I use "full quotes", not 'single ones', in DOS. So much so that I'd have to check the contextual differences. Not likely the same as *nix and/or Perl differences - it being DOS, probably entirely interchangeable with only after the "usebackq" FOR-option there being any differentiation between valid quote-characters, save perhaps that single-quotes can contain options with doubles in, without metaing, and verse vica...

But I'll also 'forget' a final quote in a line where I know the ambiguity will resolve.

Code: Select all

D:\SomeDirectory\AnotherDirectory> "c:\program files\foobar\foo" /bar "..\yet another place\bar.foo

...no need to close off the "yet another place" path with a quote, though there is (often - actually depends on how the ARGs get parsed, but best not to assume...) a need to open it.

Anyway...
MaybeBetterToUseCamelcase, but that does have potential for ambiguity, across systems. Intelligent use by a file/label author is necessary, and some people here still remember 8.3 limitations, I'm sure.

There was maybe confusion with jdbgmgr.exe and similar, but I'm reluctant to pad with either - or _ and I rarely use dashes without specific grammatical reasons, e.g. "magic-the gathering", "mgc-gthr", "Magic-theGathering" or other permutations, somewhere I'd use a dash to substitute for a colon (or colon space, or colon dashe [space]) because of the colon itself being more of a problem.

My ultimate decision wouldvbe based upon common sense (or the naïve impression of such), readability (ditto) and possibly an idea of what human/coded recipients of my decisions would have to deal with. I'm not sure I have a single preference, TBH..

### Re: Spaces in paths & filenames

Posted: Sat Jun 24, 2017 8:01 am UTC
I often do not trust programs to correctly interpret paths/names with spaces, so I try to put all files that are to be used by a program in a spaceless path. Documents (spreadsheets and stuff) can go where ever.

### Re: Spaces in paths & filenames

Posted: Sat Jun 24, 2017 8:03 am UTC
Flumble wrote:I often do not trust programs to correctly interpret paths/names with spaces, so I try to put all files that are to be used by a program in a spaceless path. Documents (spreadsheets and stuff) can go where ever.

That certainly sounds fair. Most of the time, though, I'm naming files that don't need to worry about that.

### Re: Spaces in paths & filenames

Posted: Sat Jun 24, 2017 12:10 pm UTC
The situational dependency makes an awful lot of sense to me. I don't remember the exact details now, but I've definitely had cases in the past where I'd avoid using spaces within (or anywhere above, obviously) a particular directory where I'm using tools that might be confused by them.

If I can step back from the RW-style posturing intro post, I'm mostly just glad I'm not completely crazy for using spaces in paths at all. One could say that they were significantly less popular in that Reddit thread.

### Re: Spaces in paths & filenames

Posted: Sat Jun 24, 2017 1:41 pm UTC
The one thing I try to avoid is having the names of two files be the same except for something after a space... so like "foo" and "foo bar"... because now to access "foo bar" from the CLI using tab-completion, I type "f[tab]" and it gives me foo, and now I have to type a backslash and a space to diambiguate before pressing tab again will complete the rest of the filename.

The really annoying one is using Cygwin, and trying to get to Program Files (x86)... typing pro[tab] autocompletes "Program" (since there's also ProgramData sans space), have to type backslash-space-tab to autocomplete "Files", then backslash-space-tab again to autocomplete "(x86)". If they'd just named it "Program Data" with a space it could at least be just pro-tab-f-tab-backslash-space-tab, and shave off a keystroke.

It's petty, but it irritates me a little.

### Re: Spaces in paths & filenames

Posted: Sat Jun 24, 2017 1:47 pm UTC
I don't know if this is a Bash thing, but I notice that if I type a leading quote mark, tab completion can include spaces. It'll handily close the quote before the slash and I can keep drilling down from there.

### Re: Spaces in paths & filenames

Posted: Sat Jun 24, 2017 11:47 pm UTC
Yeah, but that would require me to think ahead, and type an opening quote mark before getting into this mess...

### Re: Spaces in paths & filenames

Posted: Sun Jun 25, 2017 1:50 am UTC
Flumble wrote:I often do not trust programs to correctly interpret paths/names with spaces, so I try to put all files that are to be used by a program in a spaceless path. Documents (spreadsheets and stuff) can go where ever.
This. I am eternally paranoid. Though I'll use spaces if I'm feeling especially lazy and it's just a txt or screenshot that I'll keep on my desktop

### Re: Spaces in paths & filenames

Posted: Sun Jun 25, 2017 3:41 am UTC
Flumble wrote:I often do not trust programs to correctly interpret paths/names with spaces, so I try to put all files that are to be used by a program in a spaceless path. Documents (spreadsheets and stuff) can go where ever.
What are you doing with those spreadsheets that doesn't involve them being used by any program?!

phlip wrote:The one thing I try to avoid is having the names of two files be the same except for something after a space... so like "foo" and "foo bar"... because now to access "foo bar" from the CLI using tab-completion, I type "f[tab]" and it gives me foo, and now I have to type a backslash and a space to diambiguate before pressing tab again will complete the rest of the filename.

The really annoying one is using Cygwin, and trying to get to Program Files (x86)... typing pro[tab] autocompletes "Program" (since there's also ProgramData sans space), have to type backslash-space-tab to autocomplete "Files", then backslash-space-tab again to autocomplete "(x86)". If they'd just named it "Program Data" with a space it could at least be just pro-tab-f-tab-backslash-space-tab, and shave off a keystroke.

It's petty, but it irritates me a little.
zsh handles this the way you'd want fwiw.

### Re: Spaces in paths & filenames

Posted: Sun Jun 25, 2017 3:52 am UTC
Funnily enough, Powershell handles tab-completion with files that have spaces in them just fine, it even automatically wraps the path in double quotes for you.
Powetshell is far from perfect, but at least you can easily type /pro[tab, perhaps more than once] to get "C:\Program Files (x86)\" with the cursor after the second \.

### Re: Spaces in paths & filenames

Posted: Sun Jun 25, 2017 4:16 am UTC
Hmm, anyone know a way to get that style of tab completion in Bash? (Or something similar to Bash?)

Edit: Not the spaces, the paging-through-possibilities-with-tab.

### Re: Spaces in paths & filenames

Posted: Sun Jun 25, 2017 4:36 am UTC
Copper Bezel wrote:Hmm, anyone know a way to get that style of tab completion in Bash? (Or something similar to Bash?)

use zsh?

### Re: Spaces in paths & filenames

Posted: Sun Jun 25, 2017 4:52 am UTC
Will do! Thanks! = ]

Edit: Oh HELL yes

Edit again, having actually got my .zshrc configured to something I can live with that includes Ctrl+Backspace: Oh HELLS YES

### Re: Spaces in paths & filenames

Posted: Sun Jun 25, 2017 12:12 pm UTC
Nyktos wrote:
Flumble wrote:I often do not trust programs to correctly interpret paths/names with spaces, so I try to put all files that are to be used by a program in a spaceless path. Documents (spreadsheets and stuff) can go where ever.
What are you doing with those spreadsheets that doesn't involve them being used by any program?!

Shush, you know what I mean.
Some command line programs/scripts don't work nicely with spaces in their arguments.

Demki wrote:Funnily enough, Powershell handles tab-completion with files that have spaces in them just fine, it even automatically wraps the path in double quotes for you.

Indeed, even windows' classic command prompt has that behaviour.

Speaking of shells, I'd recommend fish over zsh for end-user stuff. blah blah blah not posix-compliant blah blah but it has rich completion out of the box. (zsh-completion-generator sounds great, but it'll have to hook into pacman for me to leave my local maximum).

### Re: Spaces in paths & filenames

Posted: Tue Jun 27, 2017 3:13 pm UTC
For whatever reason, I'm keeping zsh as my default login shell but have fish set as the default command for my terminal emulator (Tilix). It's ... really nice, with the suggestions and history and everything. I might have to actually start using some terminal apps.

### Re: Spaces in paths & filenames

Posted: Tue Jun 27, 2017 3:27 pm UTC
The times I've had problems with spaces in paths almost exclusively result from scripts that pass input to the shell.

### Re: Spaces in paths & filenames

Posted: Tue Jun 27, 2017 4:04 pm UTC
spaces_should_be_abolished_and_we_should_all_type_like_this

### Re: Spaces in paths & filenames

Posted: Tue Jun 27, 2017 9:58 pm UTC

### Re: Spaces in paths & filenames

Posted: Tue Jun 27, 2017 10:01 pm UTC
you are program

### Re: Spaces in paths & filenames

Posted: Wed Jun 28, 2017 12:26 am UTC
Got a point, though. If you are program can't handle spaces in paths, then you are program is bad.

### Re: Spaces in paths & filenames

Posted: Wed Jun 28, 2017 1:06 am UTC

### Re: Spaces in paths & filenames

Posted: Thu Jun 29, 2017 3:16 am UTC
Soupspoon wrote:By habit, I use "full quotes", not 'single ones', in DOS. So much so that I'd have to check the contextual differences. Not likely the same as *nix and/or Perl differences - it being DOS, probably entirely interchangeable with only after the "usebackq" FOR-option there being any differentiation between valid quote-characters, save perhaps that single-quotes can contain options with doubles in, without metaing, and verse vica...
Does DOS/Windows allow single quotes at all? I seem to remember it only liking double quotes, and wine cmd says "File not found" when I try to use single quotes with dir and type.

For me, it depends on whether I intend to use the file from the command line (or open it in Vim, or reference it in an HTML or CSS file or some other sort of computer code). If so, I usually use all lower case and hyphens; otherwise, I'll sometimes use capital letters and spaces.

### Re: Spaces in paths & filenames

Posted: Thu Jun 29, 2017 4:25 am UTC
chridd wrote:Does DOS/Windows allow single quotes at all? I seem to remember it only liking double quotes, and wine cmd says "File not found" when I try to use single quotes with dir and type.
Looks like Windows 7 cmd doesn't like single quotes, though I'm not sure if that extends to the C runtime (which parses command lines into argv[] for programs using a traditional C/C++ main function), and I don't have an easy way to test that quickly. So it may be the case that programs that aren't built into cmd will tend to work correctly. I do have one data point, which is that I can run winword "file with spaces.docx" and it opens, but if I use single quotes, it doesn't work and splits it at spaces. So if that's using the usual crt, it doesn't like single quotes.

PowerShell though accepts single quotes.

### Re: Spaces in paths & filenames

Posted: Thu Jun 29, 2017 6:51 am UTC
chridd wrote:Does DOS/Windows allow single quotes at all? I seem to remember it only liking double quotes, and wine cmd says "File not found" when I try to use single quotes with dir and type.
After I wrote that, I tested as soon as I got back to the first Windows machine (XP) and discovered much as you say.

Except, for some reason, the strange behaviour of the (usefully expanded) FOR options. Without "usebackq" option the (string) part is the traditional file-list, ("string") is a literal string (except likely with variable substitution) and ('string') is a command to interpolate (at last! ...so much useful stuff could now be done, previously only in *nix shell-scripts). But with "usebackq", it's now ('string') and (command), instead. And I've no idea why. It's like that in W2K too (checked that later) and I've yet to check any (named) NT version of Windows to see where the need for two different legacy schemes might have merged from. It's not as if the backquote version of FOR looks anything like the non-DOS shell counterparts, to be so confusable...

I can only imagine it's a sop to those with alternate national keyboards. Maybe «»-quotes as default, etc?

Never mind, though.

### Re: Spaces in paths & filenames

Posted: Thu Jun 29, 2017 8:40 am UTC
Unintuitively, usebackq is most useful to remove the specialness of double quotes, so you can have them inside 'a "string" literal'.

### Re: Spaces in paths & filenames

Posted: Thu Jun 29, 2017 11:05 am UTC
I should have thought of that. For some reason (maybe stemming from my reading the whole "FOR /?" documentation and thus being aware of all possible options, as soon as I found out it was so much more expanded from what it had been previously) I've always used "usebackq" when doing anything remotely complicated with new-FOR, and thus had to reinterpret the escaping of various quotes in reverse when my version of the approach caused occasional 'meta'ing problems.

### Re: Spaces in paths & filenames

Posted: Thu Jun 29, 2017 11:13 am UTC
chridd wrote:Does DOS/Windows allow single quotes at all? I seem to remember it only liking double quotes, and wine cmd says "File not found" when I try to use single quotes with dir and type.

Testing on a windows 10 machine:
cmd.exe doesn't accept 'single quotes', only "double quotes".
powershell accepts both, with 'single quotes' representing a verbatim string, and "double quotes" allows you input special characters with a backtick(like n for new line).
Basically, if you are using windows, either use powershell or download some other shell. (There is the project of getting ubuntu running on windows called windows subsystem for linux)

### Re: Spaces in paths & filenames

Posted: Thu Jun 29, 2017 12:12 pm UTC
I haven't tried it (not on Windows enough) but I've heard the system, despite being a full and real Ubuntu system running on top of NT + WSL instead of Linux, is limited in terms of what it can do back to the Windows system. There's Fedora and openSUSE coming as well, though.

One thing I don't like much about fish is that there's no way to enable Ctrl+Backspace for ^W. I bound Alt+Backspace but a decade and a half of muscle memory and the way I use the keyboard in every other app are not going to rebind so quickly. Not quite enough to make me stick to Z Shell, though, as fish's suggestion feature goes beyond tab completion into possible divinity.

### Re: Spaces in paths & filenames

Posted: Tue Jul 18, 2017 4:24 pm UTC
I almost exclusively use underscores in all file structures and file names because of my time working with a major aircraft manufacture (will remain nameless) that was (until quite recently) very reluctant to allow any changes to their various programs (usually due to aircraft certification and backwards compatibility issues). Suffice to say, some of their programs did not like spaces. Some did. In some cases you would have files used by multiple programs where it would sometimes work, sometimes not. Extremely frustrating when you are a new engineer and never used any of the programs and keep getting errors for an input file that worked just fine elsewhere. Then you ask around and its a simple "oh, remove the spaces from filenames of your input files."

Its been a long time since I've worked for that OEM but I still put underscores on EVERYTHING i use. Even the file structures for all the pictures of my kids. At this point it's kind of an OCD obsession of mine.

### Re: Spaces in paths & filenames

Posted: Tue Jul 18, 2017 8:11 pm UTC
*is definitely not writing whatever the opposite of malware is to change all underscores in paths and filenames to spaces*

### Re: Spaces in paths & filenames

Posted: Tue Jul 18, 2017 11:11 pm UTC
From bitter experience, I know that running defrag from DOS 6.22 (or earlier) on LFN-supporting FAT areas like a Win95 (or later) does a brilliant job of reducing trivial and inconsequential directory names such as "Program Files" to the handier "PROGRA~1", and likely a whole set of "MICROS~1","MICROS~2", "MICROS~3", directories beneath it...

That was a fun problem to resolve (especially when one hadva hard time finding another Win95 user, at the time, to get a 'DIR /S /someotheroptionsIforget | FIND "~" > file' copied to floppy to aid in the subsequent manual repair...). Everyone shouod try it.

### Re: Spaces in paths & filenames

Posted: Tue Jul 18, 2017 11:36 pm UTC
Soupspoon wrote:From bitter experience, I know that running defrag from DOS 6.22 (or earlier) on LFN-supporting FAT areas like a Win95 (or later) does a brilliant job of reducing trivial and inconsequential directory names such as "Program Files" to the handier "PROGRA~1", and likely a whole set of "MICROS~1","MICROS~2", "MICROS~3", directories beneath it...

That was a fun problem to resolve (especially when one hadva hard time finding another Win95 user, at the time, to get a 'DIR /S /someotheroptionsIforget | FIND "~" > file' copied to floppy to aid in the subsequent manual repair...). Everyone shouod try it.

back in those days, that shouldn't have been too much of an issue. reinstalling windows regularly was already necessary for most people, so there was an obvious easy solution.

### Re: Spaces in paths & filenames

Posted: Wed Jul 19, 2017 12:24 am UTC
It was my own machine, my first experience of post 3.x Windows, with no way of knowing how the reinstall would work (it had been pre-installed by the company I'd bought it from, something I'd avoid in a PC, these days) and still somewhat a mystery to me. Hence the silly error. I had no fall-back, and no easy method to backup of everything the reinstall would have (seemingly) wiped. No easy copying to USB (pkzip spannng onto countless HD floppies was probably my nearest option to that). But I knew that if I got a tree listing of some kind that I could return all the tilde names to original LFN ones.

(Although that install of Windows had tilde SFNs now scattered around the registry, where it had automatically gone "Can't find 'Long Name With Spaces In'... Change the reference to this similar-looking 'LONGNA~1'!" during that first, fateful bootup after my mistake, when everything had started failing and warning...)

Basically, I was a bit of a n00b with Win95 (as indeed was everybody, in that particular month in 1995!). My prior decade of DOS experience was no use. In fact was behind my 'smart' idea to use the older defrag when I hadn't been convinced that the Windows one was actually doing the job I thought it should...

(A couple of months later, though, I totally aced a job interview after being asked if I knew how to create a shortcut on the desktop, and I listed at least a half dozen different alternative methods straight off the top of my head. I think I stunned them. I got that job, and it turned into one of the best jobs I ever had. Though that might have been just been coincidence, and/or luck)

### Re: Spaces in paths & filenames

Posted: Wed Jul 19, 2017 5:50 pm UTC
Soupspoon wrote:From bitter experience, I know that running defrag from DOS 6.22 (or earlier) on LFN-supporting FAT areas like a Win95 (or later) does a brilliant job of reducing trivial and inconsequential directory names such as "Program Files" to the handier "PROGRA~1", and likely a whole set of "MICROS~1","MICROS~2", "MICROS~3", directories beneath it...

That was a fun problem to resolve (especially when one hadva hard time finding another Win95 user, at the time, to get a 'DIR /S /someotheroptionsIforget | FIND "~" > file' copied to floppy to aid in the subsequent manual repair...). Everyone shouod try it.

UGH I too remember having to deal with this.

### Re: Spaces in paths & filenames

Posted: Wed Jul 19, 2017 5:53 pm UTC
Soupspoon wrote:(A couple of months later, though, I totally aced a job interview after being asked if I knew how to create a shortcut on the desktop, and I listed at least a half dozen different alternative methods straight off the top of my head. I think I stunned them. I got that job, and it turned into one of the best jobs I ever had. Though that might have been just been coincidence, and/or luck)

Lol, look how far we have come since then. Just imagine being asked that question in an interview today. The look on your face would probably be priceless.

### Re: Spaces in paths & filenames

Posted: Sat Sep 30, 2017 4:24 pm UTC
Copper Bezel wrote:I don't know if this is a Bash thing, but I notice that if I type a leading quote mark, tab completion can include spaces. It'll handily close the quote before the slash and I can keep drilling down from there.

That's from the GNU readline library, which bash uses.

### Re: Spaces in paths & filenames

Posted: Sat Sep 30, 2017 5:54 pm UTC
Related to this, I made a fun discovery recently that both Windows and Linux will allow you to make a file with nothing but spaces in its name. And you can have multiple files in the same directory whose names are just different numbers of spaces. You need to use the -Q flag with ls to see the names properly:

Code: Select all

$ls -1Q" "" "" " Otherwise you just get: Code: Select all $ ls -1      `

In Windows, you need to do this through a terminal emulator (Git Bash worked for me), Windows Explorer won't allow you to create them, and actually throws an error if you try deleting them! So, fun prank potential there obviously. The Linux file manager I tried allowed both creation and deletion.

### Re: Spaces in paths & filenames

Posted: Sun Oct 01, 2017 4:54 am UTC
Mutex wrote:Related to this, I made a fun discovery recently that both Windows and Linux will allow you to make a file with nothing but spaces in its name.
A long time ago, when I was using the original (non-Unixy) Mac OS and was much younger, my organization strategy involved when a folder was getting too full, leaving everything where it was and creating a subfolder called " " with all the files created after that point (so this folder would be at the top of the list). I also heavily used spaces at the beginnings of file names for a similar purpose (everything's important enough that it should go at the top of the list!); also a few folders starting with ~ so they'd go at the end. I don't remember any programs having an issue with this.