0

I wrote some function that should find a directory inside a parent directory, but the thing is that it's taking to long, probably it's searching in the subdirectories as well. Here is my code:

function findMspDir () {
    mountedDir=/opt/SwDrop/
    dirToSearch=/opt/SwDrop/Repository/
    if [ ! -d $mountedDir ]; then 
        echo "The directory hasn't been found"
        exit 1;
    else
        echo "The directory is mounted"
        subDirToSearch="MSP-$versionNum"
    #   mspDir=`find $dirToSearch -name $subDirToSearch`
        mspDir=$(find /opt/SwDrop/Repository/ -name 'MSP-1.5.1.4')
        if [ "$mspDir" = "" ]; then 
            echo "The MSP directory hasn't been found"
            exit 1;
        fi
    fi
    echo "The found directory is: $mspDir"
}

I know for sure that the directory that i'm looking for is under /opt/SwDrop/Repository/ and it can't be in the subdirectories. Any idea how to solve it ?

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Alex Brodov
  • 3,365
  • 18
  • 43
  • 66

2 Answers2

3

Feel free to add -maxdepth 1 to your find command (see GNU Findutils).

tangens
  • 39,095
  • 19
  • 120
  • 139
Cyrus
  • 84,225
  • 14
  • 89
  • 153
1

find -maxdepth 1 -name "you_name" -a type d

Ivan Ivanovich
  • 880
  • 1
  • 6
  • 15