赞 | 0 |
VIP | 2 |
好人卡 | 27 |
积分 | 1 |
经验 | 26327 |
最后登录 | 2019-10-13 |
在线时间 | 953 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 120
- 在线时间
- 953 小时
- 注册时间
- 2007-4-25
- 帖子
- 805
|
- class String
- @@mb2wc = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
- def to_unicode
- len = @@mb2wc.call(65001, 0, self, -1, 0, 0) << 1
- buf =" " * len
- @@mb2wc.call(65001, 0, self, -1, buf, len)
- return buf
- end
- end
- sh_file_operation = Win32API.new('shell32', 'SHFileOperationW', 'P', 'i')
- cwd = Dir.getwd.gsub!(/\//, '\\')
- src = "#{cwd}\\测试目录\0"
- op_struct = [0, 3, src.to_unicode, 0, 4 | 0x10 | 0x0200, 0, 0, 0].pack('iIplSiii')
- sh_file_operation.call(op_struct)
复制代码 “测试目录”是希望删除的目录名,和上次一样,如果是相对于工程根目录才需要前面的 #{cwd}。
Ruby 官方实现有关文件的操作调用的大多数是 POSIX 标准的 I/O 函数,比如 Dir.foreach 就用的是 POSIX 的 opendir 函数,这些函数自然是不支持 UTF-8 的。 |
|