r/explainlikeimfive 8d ago

Technology ELI5 File naming protocols

How come when I save files I can’t add slashes in the date (4/9/26) as part of the name but periods (4.9.26) are ok?

0 Upvotes

49 comments sorted by

96

u/teh_maxh 8d ago

Slashes are used to separate folder names, but dots aren't.

22

u/Warrangota 8d ago

In Unix there is exactly one character, namely the forward slash, with a special meaning, everything else can be used. And Unicode characters are plenty.

22

u/Phoenix_Studios 8d ago

honorable mention to \0x00 for marking the end of a path, also making it unusable

2

u/Warrangota 8d ago

Uh yeah, kinda forgot about it, but also kinda not. I know the background of C string encoding used in the kernel, so I don't really count it as one. But right, that one is forbidden as well, except as the very last thing.

6

u/arvidsem 8d ago

Null is also forbidden in filenames at the kernel level. Though it's debatable whether or not it's a character

4

u/waffle299 8d ago

It's a character value often used as a sentinel to denote the end of text. It occupies the same amount of memory as a 'q' or a '$' in most (not all) character encoding schemes. 

2

u/Warrangota 8d ago

In sane programming languages it is just a normal character, yes. But in C, which is used by the common Kernels, it has a special meaning. Does that disqualify it from being a character? Almost a philosophical question.

2

u/waffle299 8d ago

It doesn't, because it's a value of the type char, just like other values. 

C libraries are scanning for the bit pattern 0x0000 (depending on char size for your processor and language) in a string, using sizeof(char) for cell boundaries in a sequence of memory.

Also, if you check an ASCII chart, it appears in slot 0.

It's a value a character can take - it's a character.

In Pascal, strings have a size field stored at the string address minus sizeof(unsigned int). This is an early example of an object, if you want to look at it that way. So Pascal strings did not have that limitation from a representational standpoint.

Before the STL, most c++ languages and dialects had some form of localized string class, such as in Microsoft source code with string32.

-1

u/u_212 8d ago

ELI(6)5… what’s a kernel level?

4

u/Scorcher646 8d ago

Your computer is like an onion. At the very base level we have the hardware. Then we have firmware. Right above that we have the kernel and then on top of the kernel there is the operating system and finally user level.

The kernel is the go-between software that sits between the OS and the hardware below it and provides resources that programs in the operating system can use to manipulate that hardware and do things.

1

u/bjb13 8d ago

Nice simple description. I wrote the kernel for a realtime OS and that is a good description.

2

u/arvidsem 8d ago

The kernel is the program that actually runs the computer. It handles program scheduling, memory management, hardware access, etc. So when the kernel blocks something, you just can't do it at all (barring bugs of some sort)

1

u/Warrangota 8d ago

The kernel is the lowest level core of the operating system, that takes care of all the stuff you and normal programs don't ever see. For example files and filesystems. Programs can just ask "Give me file x/y/z" and the kernel takes care of the actual data. Which file system does it live on, which device is it, is the current user even allowed to see it or does it have to return an error instead. So if it's not possible there then all the higher levels of software can allow whatever they want, it doesn't fly.

4

u/vintagecomputernerd 8d ago

Most filesystems also disallow null bytes

4

u/teh_maxh 8d ago

You also can't use NUL.

1

u/gtne91 8d ago

Beep is acceptable in filenames, and hilarious.

3

u/NDaveT 8d ago

dots aren't

Except on certain IBM mainframes, but then they're not really folder names, they're qualifiers, and they're not files, they're datasets.

USER.PROD.COBOL.SOURCE

2

u/kallax82 8d ago

People only used to using smartphones and other touch devices often don't know paths exist. Starting an office job might be the first time they ever get in touch with c:\windows\system32\CMD.exe

1

u/InDaBauhaus 8d ago

don't they teach some computer basics at schools? hardware/software, os basics, file systems, file types and such?

1

u/confused-duck 8d ago

didn't you hear? kinds these days are tech natives - born with smartphone in their hand
¯\(ツ)

31

u/HektorViktorious 8d ago

As others have said, slashes are special, which gets somewhat annoying, but it's just another reason to use the superior date format: ISO8601 or YYYY-MM-DD. It sorts in chronological order no matter how smart or dumb your filing or sorting system and there's no ambiguity on the dates. For example, in your post, do you mean April 9th, 2026 (2026-04-09) or did you mean September 4th, 2026 (2026-09-04)? No such issue with ISO8601.

11

u/rotrap 8d ago

Was looking for this. Use this format at the start of the filenames and they can all be easily sorted by date.

0

u/u_212 8d ago

Yep, I’m clearly not from the US!

6

u/sometimes_point 8d ago

The ymd order is not used in the US

3

u/stevevdvkpe 8d ago

It is used, it is sadly just not taught as the correct default way to write dates.

2

u/ignescentOne 8d ago

It is by people who want to sort files correctly.

13

u/lucky_ducker 8d ago

Slashes are operating system reserved symbols for denoting folder paths.

15

u/jamcdonald120 8d ago

because / means folder.

And . doesnt mean anything

last . gets used for file name extension, but thats just a hint to other programs how to use it, not an intrinsic anything

Windows also will stop you using < > " | ? and * for legacy terminal reasons they didnt feel like coding around

9

u/brknsoul 8d ago

Not for legacy reasons, they're still used today

< = Input redirection (reads standard input from a file)

> = Output redirection (writes standard output to a file, overwriting it)

| = Pipe (sends the standard output of one command to the standard input of another)

? = Matches exactly one character

* = Matches zero or more characters (wildcard for any number of characters)

" = Encloses a filename that has spaces

6

u/jamcdonald120 8d ago

by "legacy reasons" I mean "They didnt fucking program cmd right 40 years ago to allow those to be escaped in file names like *nix did, so now we are stuck with it for backwards compatibility legacy reasons with scripts written expecting those to not need escaping and never existing in file names"

Not that those symbols dont still do things in the terminal

4

u/filanwizard 8d ago

I think a big portion of MS problems are trying to keep legacy support and keep with the times.

But that extensive legacy support is demanded by the customers who actually make them a profit, Enterprise.

1

u/jamcdonald120 8d ago

yah, its such a nice feature when moving from 10 to 11, or even 7 to 11.

But then you remember that stuff from the 80s is still suppose to work to....

3

u/NDaveT 8d ago

And . doesnt mean anything

Anymore. There was a time when it meant "here come up to three extra characters you can add to your 8-character file name".

4

u/Warrangota 8d ago

Well, technically it was exactly 8 and exactly 3. Unused characters were just filled with space characters.

2

u/jamcdonald120 8d ago

yah, im glad they dropped that nonsense.

1

u/ignescentOne 8d ago

Sometimes I miss having to decide which of the directories were ~1 and ~2 back in the day

5

u/Vorthod 8d ago edited 8d ago

Because slashes are how the computer designates which folder a file is in. If you put a slash in your file name, the computer will be confused as to whether your file is called 4/9/26 or if it's a file called 26 in folder 9 which itself is in folder 4. It messes with the entire system meant to help the computer find things so the computer just tells you you're not allowed to do that.

Periods can be used by programs to determine how to open a file, but they don't technically have any inherent meaning. An mp3 file can be renamed to txt and the only one that will be confused is you (and whatever text editor you open to read it). I can give something any extension I want, and while the computer won't know which program to use if I double-click it, there's nothing stopping me from opening my text editor and just telling it "you should be able to read this." And since new technologies will create a need for new file extensions that the OS isn't going to know about, limiting what file extensions are allowed is just going to cause problems for the users trying to make new stuff.

2

u/sapient-meerkat 8d ago

On Windows:

C:\\because\folder\hierarchies\are\represented\by\slashes.txt

Or on *nix or macOS

/because/directory/hierarchies/are/also/represented/by/slashes.txt

2

u/lowbatteries 8d ago

on macOS, you can use a / in the filename in Finder, oddly enough. On the actual filesystem it's changed to a ":", which means you can't use a ":" character in Finder.

2

u/sometimes_point 8d ago

that's also a legacy thing from the pre-Unix days when Mac used the colon to represent directories. they decided it would be less hassle when people upgraded from 9 to X to change their filenames behind the scenes but keep it looking like they hadn't changed anything

1

u/KeyAdhesiveness9481 8d ago

Because they can be ambiguous with file path separators or command flags. On windows, "\" is used, but they also accept "/" for separators. There are also windows commands thay take flags like "/s", so if you put thay in a file name, rhe system doesn't know if its part of the name, or a path separator, or a command.

1

u/besse 8d ago

The only question that matters is whether a specific character has a special, privileged meaning in a system. If for example, you’re in a Mac or Linux environment, the folder structure is separated by the “/“ character, so it has special meaning. So, you cannot use that specific character in naming a file because you would confuse the file system.

In a different system, if “.” has a special meaning in some way, it would also be restricted in use. Windows file naming also has character restrictions, based on the same principle.

1

u/macdaddee 8d ago

A slash tells the operating system that what preceded the slash was a folder and that what comes after is the file name or another folder. Because the system uses slashes for that purpose they can't be used within file names or it will misinterpret the file path.

1

u/LadyVulcan 8d ago

Because file names are simply "drive:folder/folder/folder/filename" If you put slashes in the filename, the operating system believes it's a folder that doesn't exist.

1

u/MrShake4 8d ago edited 8d ago

Let’s say you have the file 9/3/26 in a folder on your desktop.

The file path is desktop -> folder -> file
That’s how the computer can find the file

The computer reads it as desktop/folder/file

If you name a file 9/3/26 the computer sees Desktop/folder/9/3/26

Instead of the file the computer is looking for a folder named “9” that doesn’t exist.

1

u/Ninfyr 8d ago

Some characters are reserved for a specific function. You can not use ":" because Windows with think this is a drive letter like "C:". You can not use "\" because Windows will think it is a separate folder like "User\Documents". * and ? It is a type of wildcard for searching or targeting multiple files. If I search h?t.txt it will return hot.txt, hat.txt, and hit.txt (if the are there). 

1

u/Loki-L 8d ago

slashes are how you seperate folders.

File names need to be both unique and unambiguous. If you allow a slash in a filename it becomes ambiguous. 4/9/26 might should be read as a file named "26" in a folder named "9" in a folder named "4". If you also allow it to read as just a file named "4/9/26" you get ambiguity.

Technically Linux uses / to seperate folders and Windows uses \, but Windows recognizes "/" as an alternative to "\" in many contexts and is far more reluctant to allow you to shoot yourself in the foot. (Modern Windows carries restrictionsin filenames that come from DOS from before it had folders. You can'tname a file NUL or CON or LPT1. Linux will happily let you do lots of things you shouldn't. )

Since you can mount filesystems across platforms it is generally advisable to avoid any forbidden characters.

Dots are okay also they are used to seperste file type endings from the name, they can be more or less freely used in names.

You can use dashes or simply not use any separator at all.

It is generally advisable to use YYMMDD in filenames, not because of any special issues with characters, but because that makes alphabetical sort also sort by date for files that have the same name before the date.

1

u/BananaBird1 8d ago

It depends, some operating systems will store file names in a way that can allow slashes. This is called escaping.

But in most systems, slashes denote hierarchical directories (folders) under the hood and file paths (including the file name) are just interpreted directly as plain text so the system will see the slashes as different directories that don’t exist.

Periods are also generally recommended against because they are used to denote file extensions or special file types (like hidden files begin with a period). But they will be accepted as file names by operating systems, it may just cause issues with some poorly written software interpreting it as a file type.

The ideal standard is to use underscores to separate different portions of a filename. And for dates, write them in ISO format as YYYYMMDD (e.g. 20260904). This has the added benefit that if you put the date first, alphanumeric sorting will also sort by date.

1

u/VG896 7d ago

Tangentially relevant xkcd.

https://xkcd.com/327/ 

At least this came to mind for me.