加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

在创建文件名时,ruby – Colon(:)显示为正斜杠(/)

发布时间:2020-12-16 20:43:25 所属栏目:百科 来源:网络整理
导读:我使用日期和时间标记我正在创建的新文件,但是当我查看文件时,冒号是一个正斜杠.我使用10.7在Mac上开发 这是我使用的代码: File.open("#{time.hour} : 00,#{time.month}-#{time.day}-#{time.year}","a") do |mFile| mFile.syswrite("#{pKey} - #{tKey}: n"
我使用日期和时间标记我正在创建的新文件,但是当我查看文件时,冒号是一个正斜杠.我使用10.7在Mac上开发

这是我使用的代码:

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

这是输出(假设时间是1pm):

13 / 00,11-8-2012

为什么会发生这种情况,我该如何解决?我想要的输出是:

13:00,11-8-2012

解决方法

曾经在Mac OS X之前,:是目录分隔符而不是/.显然OS X 10.7仍在努力修复这样的程序.我不知道如何解决这个问题,如果你真的需要:在那里.我会省略:-).

编辑:经过更多的搜索,this USENIX paper描述了发生了什么.他们明显使用的规则是:

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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读