开发者

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

开发者 https://www.devze.com 2023-03-25 08:13 出处:网络
I\'m trying to catalog a bunch of files on OSX using ruby, essentially doing this: hash = Digest::SHA1.hexdigest(File.open(fullpath).read)

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

精彩评论

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