Unix find命令-相当于Unix中的.net文件.Exists和Directoty.Exists

Unix find命令-相当于Unix中的.net文件.Exists和Directoty.Exists,unix,find,Unix,Find,在.net应用程序中,我们必须对Unix系统运行文件操作命令。我正在尝试使用等效的File.Exists和Directory.Exists 到目前为止,在.net中使用ssh可以通过以下方式工作: 仅查找具有匹配名称的文件: find /folder/subfolder -maxdepth 1 -type f -iname test.mov find /folder/subfolder -maxdepth 1 -type d -iname test 仅查找具有匹配名称的目录: find /f

在.net应用程序中,我们必须对Unix系统运行文件操作命令。我正在尝试使用等效的File.Exists和Directory.Exists

到目前为止,在.net中使用ssh可以通过以下方式工作:

仅查找具有匹配名称的文件:

find /folder/subfolder -maxdepth 1 -type f -iname test.mov
find /folder/subfolder -maxdepth 1 -type d -iname test
仅查找具有匹配名称的目录:

find /folder/subfolder -maxdepth 1 -type f -iname test.mov
find /folder/subfolder -maxdepth 1 -type d -iname test
问题-是否可以在不拆分完整路径的情况下执行上述操作

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

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或not ok

[ -f /path/to/filename ]  && exit 0 || exit 1
“查找”在找不到命名目录或文件时不返回错误