Windows和Unix中的文件扩展名有哪些规则?

时间:2022-10-29 20:10:46

i'm currently using File::Basename fileparse to separate out a file's directory, base file name and it's extension using something like this:

我目前正在使用File :: Basename fileparse来分离文件的目录,基本文件名和它的扩展名,使用类似这样的东西:

my($myfile_name,$mydirectory, $file_extension) = fileparse($$rhash_params{'storage_full_path_location'},'\..{1,4}');

But see that there's a variation where you can actually provide a array of suffixes to the function, the array would contains all the known file extension.

但是看到有一个变体,你可以实际为函数提供一个后缀数组,该数组将包含所有已知的文件扩展名。

So i'm trying to find a safe way to do this as i've seen that i've got some strange file names to process, i.e. file.0f1.htm, etc.

所以我试图找到一种安全的方法,因为我已经看到我有一些奇怪的文件名要处理,即file.0f1.htm等。

Question:

  1. Is there a list of commonly used extension for Windows and Unix systems? But in my case it's mainly for Windows.
  2. 是否有Windows和Unix系统常用扩展名列表?但就我而言,它主要用于Windows。

  3. And is it safe to assume that all file names in Windows should have an extension ending with three letter characters?
  4. 并且可以安全地假设Windows中的所有文件名都应该有一个以三个字母字符结尾的扩展名吗?

And if there's an even better way to do this, please share.

如果还有更好的方法,请分享。

Thanks.

Updates:

So obviously i must be drunk to forgot about those other extension. :) Thus i've updated the current regex to allow from 1-4chars.

显然我必须喝醉才能忘记其他扩展。 :)因此我已经更新了当前正则表达式允许1-4chars。

In this case, how should i change my regex line to properly match it? Or is it an even better idea to look for all those commonly used extension from google and put them into an array to be passed to the function instead? My users are usually either students or teachers.

在这种情况下,我应该如何更改我的正则表达式线以正确匹配它?或者更好的想法是从谷歌中寻找所有常用的扩展并将它们放入一个数组中以传递给函数?我的用户通常是学生或老师。

2 个解决方案

#1


1. Is there a list of commonly used extension for Windows and Unix systems? But in my case it's mainly for Windows.

1.是否有Windows和Unix系统常用扩展名列表?但就我而言,它主要用于Windows。

Yes, loads, all over the internet: http://www.google.com/search?q=common+file+extensions

是的,加载,遍布互联网:http://www.google.com/search?q = common + file +extensions

2. And is it safe to assume that all file names in Windows should have an extension ending with three letter characters?

2.可以安全地假设Windows中的所有文件名都应该有一个以三个字母字符结尾的扩展名吗?

No, it's perfectly possible to use '.c', '.java', etc in Windows.

不,在Windows中使用'.c','。java'等是完全可能的。

#2


There are several fault assumptions in your code:

您的代码中有几个错误假设:

  • files need not have extensions. For example most binary executables on Unix/Linux/... don't have an extension at all. They are simply calls "bash", "wget", "sed", "Xorg", ...
  • 文件不需要扩展名。例如,Unix / Linux / ...上的大多数二进制可执行文件根本没有扩展名。它们简称为“bash”,“wget”,“sed”,“Xorg”,......

  • extensions need not be three characters long, as @Alnitak already told you: ".c", ".java", ".mpeg", ".jpeg", ".html" are all perfectly fine and rather wide-spread extensions
  • 扩展不需要三个字符长,因为@Alnitak已经告诉过你:“。c”,“。java”,“。mpeg”,“。jpeg”,“。html”都是完美的,相当广泛的扩展

  • cutting at the last "." is probably saver, but can still fail for files with no extensions or with multiple (or multi-part) extensions such as ".tar.gz", "tar.bz2", which occur rather often in the Unix/Linux/...-World
  • 切割到最后“。”可能更安全,但对于没有扩展名的文件或多个(或多部分)扩展名的文件仍然会失败,例如“.tar.gz”,“tar.bz2”,它们经常出现在Unix / Linux / .. 。-世界

#1


1. Is there a list of commonly used extension for Windows and Unix systems? But in my case it's mainly for Windows.

1.是否有Windows和Unix系统常用扩展名列表?但就我而言,它主要用于Windows。

Yes, loads, all over the internet: http://www.google.com/search?q=common+file+extensions

是的,加载,遍布互联网:http://www.google.com/search?q = common + file +extensions

2. And is it safe to assume that all file names in Windows should have an extension ending with three letter characters?

2.可以安全地假设Windows中的所有文件名都应该有一个以三个字母字符结尾的扩展名吗?

No, it's perfectly possible to use '.c', '.java', etc in Windows.

不,在Windows中使用'.c','。java'等是完全可能的。

#2


There are several fault assumptions in your code:

您的代码中有几个错误假设:

  • files need not have extensions. For example most binary executables on Unix/Linux/... don't have an extension at all. They are simply calls "bash", "wget", "sed", "Xorg", ...
  • 文件不需要扩展名。例如,Unix / Linux / ...上的大多数二进制可执行文件根本没有扩展名。它们简称为“bash”,“wget”,“sed”,“Xorg”,......

  • extensions need not be three characters long, as @Alnitak already told you: ".c", ".java", ".mpeg", ".jpeg", ".html" are all perfectly fine and rather wide-spread extensions
  • 扩展不需要三个字符长,因为@Alnitak已经告诉过你:“。c”,“。java”,“。mpeg”,“。jpeg”,“。html”都是完美的,相当广泛的扩展

  • cutting at the last "." is probably saver, but can still fail for files with no extensions or with multiple (or multi-part) extensions such as ".tar.gz", "tar.bz2", which occur rather often in the Unix/Linux/...-World
  • 切割到最后“。”可能更安全,但对于没有扩展名的文件或多个(或多部分)扩展名的文件仍然会失败,例如“.tar.gz”,“tar.bz2”,它们经常出现在Unix / Linux / .. 。-世界