When calling the pathExtension method on a string that contains something such as “example.tar.gz” I get “.gz” as the result. I can do some string manipulation to get the real extension, but I’m number wondering if there is a built in method that I’m overlooking? (I have checked the docs, but I don’t see anything).
When calling the pathExtension method on a string that contains something such as example.tar.gz
Share
Obviously
pathExtensionis working as expected in this case. The documentation forpathExtensionsays:I can see where you are coming from with your example of a tarred gzipped file. However, I would say that
.gzis the extension. Unzipping the file (withgzip) will result in a.tarfile which can be extracted withtar.I assume that the convention of naming files with the
.tar.gzextension started beforetarwas able to also perform the gzip compression. Thegzipapplication appends.gzto the filename of the file being compressed. For example, gzipping a log file,access.log, will result in a file calledaccess.log.gz.The
.tgzextension has been used for tarred gzipped files particularly where the filename needs to be preserved on file systems that would mangle the extension (e.g. DOS).