创建文件名时,冒号(:)显示为正斜杠(/) [英] Colon (:) appears as forward slash (/) when creating file name

查看:498
本文介绍了创建文件名时,冒号(:)显示为正斜杠(/)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用日期和时间来标记正在创建的新文件,但是当我查看该文件时,冒号是一个正斜杠.我正在使用10.7+的Mac上进行开发

I am using date and time to label a new file that I'm creating, but when I view the file, the colon is a forward slash. I am developing on a Mac using 10.7+

这是我正在使用的代码:

Here is the code I'm using:

 File.open("#{time.hour} : 00, #{time.month}-#{time.day}-#{time.year}", "a") do |mFile|
        mFile.syswrite("#{pKey} - #{tKey}: \n") 
        mFile.syswrite("Items closed: #{itemsClosed} | Total items: #{totalItems} | Percent closed: % #{pClosed} \n") 
        mFile.syswrite("\n")
        mFile.close
     end

以下是输出(假设时间是下午1点):

Here is the output (assuming the time is 1pm):

13 / 00, 11-8-2012

为什么会发生这种情况,我该如何解决?我希望输出为:

Why is this happening and how can I fix it? I want the output to be:

13:00, 11-8-2012

推荐答案

从前,在Mac OS X之前,:是目录分隔符而不是/.显然,OS X 10.7仍在尝试修复此类程序.如果您确实需要:,我不知道如何解决此问题.我会忽略它:-).

Once upon a time, before Mac OS X, : was the directory separator instead of /. Apparently OS X 10.7 is still trying to fix up programs like that. I don't know how you can fix this, if you really need the : to be there. I'd omit it :-).

经过更多搜索,此USENIX论文描述了正在发生的事情.他们显然使用的规则是:

After a bit more searching this USENIX paper describes what is going on. The rule they use apparently is this:

另一个明显的问题是HFS +(冒号,:")和UFS之间的路径分隔符不同 (斜杠"/").这也意味着HFS +文件名可能包含斜杠字符而不是 冒号,而UFS文件名则相反.这很容易解决,尽管它 涉及来回转换字符串.内核VFS中的HFS +实现 读取和写入磁盘时,层将冒号转换为斜线,反之亦然 格式.因此,在磁盘上,分隔符是冒号,但在VFS层(因此 在它和内核(例如libc)之上,是一个斜线.但是,传统的Mac OS 工具包期望冒号,因此在BSD层之上,核心Carbon工具包又做了一个 翻译.结果是Carbon应用程序看到冒号,其他所有人看到 斜线.在极少数的文件名情况下,这会导致用户可见的精神分裂症 包含冒号字符,在Carbon应用程序中显示为斜杠字符,但 BSD程序和可可应用程序冒号.

Another obvious problem is the different path separators between HFS+ (colon, ':') and UFS (slash, '/'). This also means that HFS+ file names may contain the slash character and not colons, while the opposite is true for UFS file names. This was easy to address, though it involves transforming strings back and forth. The HFS+ implementation in the kernel's VFS layer converts colon to slash and vice versa when reading from and writing to the on-disk format. So on disk the separator is a colon, but at the VFS layer (and therefore anything above it and the kernel, such as libc) it's a slash. However, the traditional Mac OS toolkits expect colons, so above the BSD layer, the core Carbon toolkit does yet another translation. The result is that Carbon applications see colons, and everyone else sees slashes. This can create a user-visible schizophrenia in the rare cases of file names containing colon characters, which appear to Carbon applications as slash characters, but to BSD programs and Cocoa applications as colons.

这篇关于创建文件名时,冒号(:)显示为正斜杠(/)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆