LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   about subdirectories (https://www.linuxquestions.org/questions/programming-9/about-subdirectories-526763/)

nesta 02-08-2007 10:43 AM

about subdirectories
 
hi folks,
i want to know a shell command that enables me to check that my current directory have some directories or not
and asolutly their names if possible?

i have tried test command but i cant do it.

thanks in advance.

ntubski 02-08-2007 11:23 AM

Code:

find . -maxdepth 1 -mindepth 1 -type d
or
Code:

for file in * .*; do if [ -d "$file" ] ; then echo "$file"; fi; done

nesta 02-08-2007 04:02 PM

thank u for wonderful answer
it is really so useful for me ,
i have used find command u sent but,
i want to save the result into a shell array variable

thanks in advance

nesta 02-08-2007 04:09 PM

when i tried the following:

directories=`find . -maxdepth 1 -mindepth 1 -type d`
echo $directories


i got ./folder1 ./folder2

but i want to access each of (folder1 and folder2)alone,how can i do that
i.e. i want to assign ./folder1 to a variable while
./folder2 to another variable

Tischbein 02-08-2007 06:18 PM

Here's a generic solution for getting the arguments one at a time. You can then put them into array cells, run code on them, whatever you please.

Code:

i=0

find . -maxdepth 1 -mindepth 1 -type d |\
while read dirname
do
    i=$((i+1))
    echo "Find number $i is called $dirname"
done



All times are GMT -5. The time now is 09:11 AM.