osx:从字符串中删除所有不能用于 osx 中文件名的字符
是否有一些标准方法可以从字符串中删除不能用于 osx 中文件名的所有字符?您被允许使用的字符是否对应于某些常用类别? (我知道定义允许的字符列表是可能的,但我希望能够使用多种语言(中文等)的文件名,所以这会有点痛苦。) 也可以在 ubuntu 中使用的解决方案,那就太好了。
Is there some standard method to remove all characters from string that cannot be used for a filenames in osx? Does the characters you are allowed to use correspond to some commonly used category? (I know defining a list of allowed characters would be possible, but I want to be able to use filenames from several languages (chinese, among others), so this will be a bit of a pain.) A solution that works in ubuntu too, would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我使用以下代码将任意字符串转换为有效的文件名。它遵循与将 URL 拖动到桌面时创建 webloc 文件所应用的规则类似的规则(如果不相同)。
在达尔文级别,“/”字符存储为“:”字符(反之亦然)。出于美观原因,它们在此处被删除。
I use the following code to convert a arbitrary string into a valid filename. It follows similar rules (if not the same) to those applied to creating a webloc file when dragging a URL to the Desktop.
At the Darwin level "/" characters are stored as ":" characters (and vice versa). They are removed here for cosmetic reasons.
允许除“/”之外的任何 unicode 字符。因为您的问题也与 AppleScript 相关,所以我必须通知您,Macintosh 路径显示“/”,而实际字符是“:”。因此,当您告诉 Finder 在路径“Macintosh HD:Users:shortname:Desktop:images/movies”创建文件夹时,在 POSIX 中它将看起来像“/Users/shortname/Desktop/images:movies”。
Any unicode character except for the "/" is allowed. Because your question is AppleScript related as well I have to inform you that Macintosh Paths displays a "/" while the actual character is ":". So when you tell the Finder to make folder at path "Macintosh HD:Users:shortname:Desktop:images/movies" then in POSIX it will look like "/Users/shortname/Desktop/images:movies".