Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
260 views
in Technique[技术] by (71.8m points)

filenames - Do dotfiles have a file extension?

Do dotfiles, such as .htaccess .gitignore and .config, have a file extension and no filename or are they considered to have a filename and no extension?


I'm trying to implement some utility functions in PHP, which is notorious for doing things wrong and I noticed that PHP's pathinfo function considers dotfiles to have a file extension and no filename, whereas node's path.extname considers dotfiles to have a filename and no extension.

I'm unclear as to whether a standard exists, or whether this amounts to developer preference.

question from:https://stackoverflow.com/questions/32173890/do-dotfiles-have-a-file-extension

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You pays your money and you takes your pick: Yes, No, Maybe.

It comes down to your definition of 'extension'.

  • Is it "anything after the last dot in the name"? If so, those files have no name and are all extension.
  • Is it "anything after a dot that isn't the first character in the name"? If so, those files don't have an extension.
  • If you use some other definition, then the answer will need to be adjusted accordingly.

Remember that SCCS files used a prefix s. (amongst others; you'd see p. files too — and there were many transient file names with other prefixes). Does an SCCS file s.something have an extension or a prefix? (With s.source.c, it is reasonably straight-forward; there's a prefix, a name and an extension or suffix, or you could ignore the prefix as a special case and the name is s.source and the extension is .c.) What about the default executable name, a.out? What about a name such as ..dot; does it have an extension, and if so, what is it?

Note that the answer on DOS was more formalized. There the file system used to enforce (once upon another millennium or so) names with 8.3 and the extension was tangible. But that's a bygone era for the most part (and there are few who miss it).

Anthony Arnold and paxdiablo both noted that names ending with .tar.gz exist — what's the extension on such files?

If you treat the extension of somecode-8.76.tar.gz as anything other than .gz, you are opening yourself up to a bag'o'worms. The contained file is somecode-8.76.tar; that itself can be reasonably said to have an extension of .tar. Defining the extension of the whole gzipped tar file as .tar.gz raises the question of "why isn't it .76.tar.gz" and also means that you need to revisit the SCCS file naming convention. Absorbing the .76 portion of the name into either .76.tar.gz or .76.tar as a suffix is making life complex indeed. It's a valid question, but anything other than "an extension is the string from the last dot to the end of the name" is fraught indeed — or requires interpretation of the meaning of the extension, and gets into another complex area that it generally is better to avoid.

Note that Unix at the O/S or file system level doesn't care about the extension on files. Programs can decide they care about extensions, but that's up to the program. The extension is an indicator of the file type; it is not definitive. That's why the file program exists to identify the contents of files. It looks at the contents of the file to identify the content; it doesn't pay attention to the file extension (so it doesn't have to decide what the extension is, either).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...