If you are looking for the shell script method, you can use one of the below methods.
Method 1 : Read Input from the User After Running the Script.
#!/usr/bin/bash
echo " Enter the Directory Name From which you need to get the list of the Files "
read directoryPath
echo " The Directory You have entered is [ $directoryPath ]"
if [ -d "$directoryPath" ]; then
ls -l $directoryPath | grep -v total
else
echo "The Directory Entered is Invalid or does not exist !!! "
fi
Method 2 : Pass the Input as argument in command line :
#!/usr/bin/bash
if [ "$#" -lt 1 -o "$#" -gt 2 ]; then
echo " usage : $0 <directoryname> "
exit 0;
fi
if [ -d $1 ]; then
ls -l $2 | grep -v total
else
echo " Invalid Directory Name or Directory Does nto exist !!!"
fi
</directoryname>
Both these are designed to take only one value as input for the Directory name. You can make necessary Modification so that as the same time more directories can be given as input.
If you are looking for getting the directory list using programming languages like C/C++ then @Richard MacCutchan 's answer sounds great..
BR//
Harsha