判斷指定目錄是否有檔案
linux 中如何判斷指定目錄下是否有檔案(包括隱藏檔案和符號鏈結)呢?
指令碼名:decide_blank_folder.sh
指令碼內容:
shell**
#!/bin/sh
# whether the specified folder has files,including symbolic file and hidden file
is_blank_dir_yes=2
is_blank_dir_no=5
ishasfileindir()
is_blank_folder_compl()
if [ -z "$1" ];then
echo "no argument";
exit 255
fi
is_blank_folder_compl "$1"
retval=$?
echo "return value: $retval"
if [ $retval -eq $is_blank_dir_yes ];then
echo "has no file(s)"
else
if [ $retval -eq $is_blank_dir_no ];then
echo "has file......."
fi
fi
測試如下:
[root@localhost test]# ./decide_blank_folder.sh abc/
return value: 2
has no file(s)
知識點補充:
(1)如何檢視隱藏檔案?
使用ls -a
(2)`find "$fold_name" ! -type d` 中的感嘆號表示什麼?
表示否定,即搜尋除資料夾之外的所有內容,搜尋時排出資料夾。
C 判斷指定檔案是否存在
private void button2 click object sender,eventargs e else 注 使用file.exists方法,需要引用 system.io 命名空間 語法 public static bool exists string path 引數 path 型別 sy...
c 判斷指定檔案是否存在的簡單實現
複製 如下 private void button2 click object sender,eventargs e else 注 使用file.exists方法,需要引用 system.io 命名空間 語法 複製 如下 public static bool exists string path 引...
判斷指定IP是否在指定IP段中
最近在做乙個訪問控制的功能,只允許指定ip,或者ip段中的ip訪問。下面方法用來判斷指定ip是否在指定ip段中 已通過測試 判斷ip是否在某個網段內 param ip param network return bool function ipinnetwork ip,network return f...