如何检查文件是否存在 [英] How to check for file existence

查看:73
本文介绍了如何检查文件是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在一个Ruby类/方法,可以在其中传递完整路径" home/me/a_file.txt,以识别它是否为有效的文件路径?

Is there a Ruby class/method where I could pass "a full path", home/me/a_file.txt, to identify whether it is a valid file path?

推荐答案

查看路径名,尤其是

Check out Pathname and in particular Pathname#exist?.

文件及其

File and its FileTest module are perhaps simpler/more direct, but I find Pathname a nicer interface in general.

这篇关于如何检查文件是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆