Reputation: 15940
My Application has a folder structure like
/PNRPHD1/ex1/11.txt
/PNRPHD1/ex1/ex2/11.txt
/PNRPHD1/ex1/ex2/ex3/23.txt
/PNRPHD1/ex1/ex2/34.txt
/PNRPHD1/ex1/ex3/sp4/sp3/4334.txt,
but /PNRPHD1 is main folder, within that folder I need to iterate every time and go to the last level and check if the file exists or not,in that Directory or not, if File is the content of directory, then i need to build that path and come out of that loop. and I should have the above mentioned path as the output of the variable.
Note: In the above directory structure, each directory can contain either a other Sub directory or a File, it wont have both
Can any one suggest I was trying to do that in a IF loop, But that is getting too much of code, I wanted to implement with minimum code
DIR_REG = /PNRPHD1;
ls -p $DIR_REG | while read -r dir
do
echo "directory under is -- " ${dir} >>${DEBUG_LOG_FILE}
BUP="/cygdrive/d/psoft/${PSFT_SID}/${dir}";
ls -p $BUP | while read -r dir1
do
if [ -f "${BUP}/${dir1}" ]; then
mkdir -p "${BUP}backup"
echo "level of directory -- " ${BUP}/${dir1} >>${DEBUG_LOG_FILE}
else
echo "level of directory -- " ${BUP}/${dir1} >>${DEBUG_LOG_FILE}
fi
done
done
I am looking for a better shell script and concise one, which does the required task..
Updated :
I am expecting the output of my loop should have a variable output in each iteration.
1st Case : /ex1/
2nd case : /ex1/ex2
3rd Case : ex1/ex2/ex3/
4th Case : /ex1/ex2/ex3/
5th Case : /ex1/ex3/sp4/sp3/
Upvotes: 0
Views: 1941
Reputation: 15940
I tried with the find command find . -type f -print; to list all the type of files
and
find . -type d -print; to list all the type of directories
once we get the list of files or directories, use DirName command to get the path
Upvotes: 0