开发者

How can I escape filenames in ruby (osx) for open/read/hexdigest?

I'm trying to catalog a bunch of files on OSX using ruby, essentially doing this:

hash = Digest::SHA1.hexdigest(File.open(fullpath).read)

This is failing on filenames that contain apostroph开发者_如何学编程es, which are legal characters for a filename.

The File.open works, but I get an "Errno::EINVAL: Invalid argument" error from the read. The filenames are coming directly out of a Dir[] glob.

I've tried escaping them with backslashes, but that doesn't seem to work.

What's the right way to escape these filenames?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜