Midhun
Midhun

Reputation: 375

Check if passed argument is file or directory

I wanted to get into the directory which is starts with DL and go to INBOUND directory then Check if directory having files or directory.If files then count the no of files and write it into IWCO.txt file along with directory name. If directory then get in to all the directory count no of files in it then write it into a IWCO.txt file along with directory name.

for ex:

DL_ComedyCentralRecords/INBOUND/Chris Hardwick FUNCOMFORTABLE/abc.txt
DL_Paracadute/INBOUND/acb.txt def.txt

i want output like

DL_ComedyCentralRecords/INBOUND/Chris Hardwick FUNCOMFORTABLE|1
DL_Paracadute/INBOUND|2

Upvotes: 1

Views: 403

Answers (1)

aurelius
aurelius

Reputation: 4076

[ -f "$filename" ] is true for files,

[ -d "$dirname" ] is true for directories.

if [ -d "$filename" ] ; 
   then echo "$filename"/ ; 
elif [ -f "$filename" ] ; 
   then echo "$filename"'*' ; 
fi

Upvotes: 2

Related Questions