2012-05-22 67 views
0

在我们的.net应用程序中,我们必须对Unix系统运行文件操作命令。我试图有相当于File.Exists和Directory.Exists。Unix查找命令 - Unix中的.net File.Exists和Directoty.Exists等价物

在.NET中使用SSH,一定要在下列方式工作至今:

仅查找匹配名称的文件:

find /folder/subfolder -maxdepth 1 -type f -iname test.mov 

仅查找匹配名称目录:

find /folder/subfolder -maxdepth 1 -type d -iname test 

问题 - 是否可以在不拆分完整路径的情况下执行上述操作?

拆分路径并不是什么大不了的,但现有的生产服务只接受命令运行和路径。

回答

0
test -d /path/to/directory_name 
[ -d /path/to/directory_name ] 

返回true或false - 即directory.exists

test -f /path/to/filename 
[ -f /path/to/filename ] 

相同的文件

您可以使用这些构造返回OK或不正常

[ -f /path/to/filename ] && exit 0 || exit 1 

发现确实当找不到指定的目录或文件时不返回错误