linux shell程序,如何输入一个文件名判断它是文件夹还是文件?

linux shell程序,如何输入一个文件名判断它是文件夹还是文件?,第1张

//是目录不含洞是文件

#! /bin/bash

# filename:FileType.sh

read -p "Please input the filename :" filename

fpath=$filename

if [ -d $fpath ]

then

echo "谈渗枯$fpath is a direstory."

elif [ -e $fpath ]

then

echo "喊宴$fpath is a file."

else

echo "$fpath is NOT a file or direstory."

fi

# 目录兄枣存羡孝拆在

Test-Path $path -PathType Container

[System.IO.Directory]::Exists($path)

# 文件存在慎裂

Test-Path $path -PathType Leaf

[system.IO.File]::Exists($path)


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/12156989.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-21
下一篇 2023-05-21

发表评论

登录后才能评论

评论列表(0条)

保存