shell判斷文件是否是文件夾
❶ Powershell 寫一腳本判斷在一特定路徑下是否存在指定的文件夾
$filelist=gc "file.txt" #獲取要檢查的文件列表
$csvs= new-object collections.arraylist #創建一個arraylist對象
foreach($file in $filelist){
$csv=new-psobject|select yes,no
if([io.Directory]::Exists($file)){ #判斷文件是否存在
$csv.yes=$file
}else{
$csv.no=$file
}
$null=$csvs.add($csv)
}
$csvs|Export-Csv file.csv -notype -Encoding oem #導出成csv文件
❷ Shell腳本判斷是文件還是目錄怎麼寫
#!/bin/bash
if[-d$1]
then
echo"$1isadirectory."
exit
elif[-f$1]
then
echo-n"$1isafile,"
if[-L$1]
then
echo"anditisalsoasymboliclink."
A=`ls-L$1`
if[-e$A]
then
echo"Symboliclinkexist."
else
echo"Symboliclinknotexist."
fi
exit
else
echo"butitisnotasymboliclink."
exit
fi
fi
❸ shell腳本判斷文件夾下是否有文件
search_dir=/tmp/test
include_subdir=1
if[$include_subdir-eq1];then
n=$(find$search_dir-typef-execsh-c'printf"%s ""$1";kill"$PPID"'sh{};|grep-v"Terminated"|wc-l)
else
n=$(find$search_dir-maxdepth1-typef-execsh-c'printf"%s ""$1";kill"$PPID"'sh{};|grep-v"Terminated"|wc-l)
fi
結果 n 為 0 表示指定目錄下面沒有文件,否則有文件。如果不需要檢查指定目錄下的子目錄,把 include_subdir 置為 0 即可。find 命令中較復雜的那部分是為了實現找到第一個文件時就停止查找,避免檢查有大量文件的目錄時影響性能。
❹ liunx 下的shell語句 if [ ! -d /$1/$2/$3/ ]是什麼意思
liunx 下的shell語句 if [ ! -d /$1/$2/$3/ ]這是判斷某文件夾是否存在,$1, $2, $3都是變數,操作方法如下:
1、判斷文件的基本格式。[ 操作符 文件或目錄 ]。
❺ CSHELL如何完成這樣的功能,判斷一個文件夾下面是否存在文件
可以用find來查找,根據查找的返回狀態變數來判斷
#!bin/csh
find . -name filename
if($? == 0) # C shell 的if判斷不知道是不是這樣,具體的給忘了,狀態變數是$?
echo "filename 存在"
else
echo "filenam 不存在"
endif
❻ powershell判斷是文件夾還是文件
#目錄存在
Test-Path$path-PathTypeContainer
[System.IO.Directory]::Exists($path)
#文件存在
Test-Path$path-PathTypeLeaf
[system.IO.File]::Exists($path)
❼ shell判斷文件夾內是否有文件
if [ `ls directory | wc` -eq 0 ]
then
echo "文件夾為空"
fi
#directory是要判斷的文件夾,'是ESC鍵下面那個鍵不是單引號,手機不好打
❽ linux shell程序,如何輸入一個文件名判斷它是文件夾還是文件
//是目錄不是文件夾
#! /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
❾ shell判斷文件夾是否存在
Shell中的test命令用於檢查某個條件是否成立,它可以進行數值、字元和文件三個方面的測試,那麼如何使用shell來判斷文件夾是否存在呢?今天小編就就帶大家來看看吧。文件夾不存在則創建
如果身邊就有電腦,可以跟著上文一起操作,這樣可以更好的理解喔
本文章基於Lenovo品牌、Windows10系統撰寫的。