我正在使用普通标志使用 wget 将文件保存到 ext2 分区。检索他们的名字有时会失败:
s = `find "#{@dir}" -type f -printf "%T@\t::::\t%s\t::::\t%p\n" |sort`
s.each_line {|l|
file_name = l.chomp.split("\t::::\t")[2] #=>
# ...66:in `split': invalid byte sequence in UTF-8 (ArgumentError)
}
测试:
l.encoding #=> UTF-8
l.valid_encoding #=> false
l.inspect #=> "...St. Paul\xE2%80%99s Cathedral..."
Iconv.conv('utf-8', 'utf-8', l) #=>
# ...77:in `conv': "\xE2%80%99s Cathedr"... (Iconv::IllegalSequence)
如何获取文件名并删除文件?
忘了提一下,在 bash 中,文件看起来像:
index.php?attTag=St. Paul?%80%99s Cathedral
将此字符串粘贴回 ls 不会返回此类文件或目录。