![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| mail function problem | jwholey | Shell Programming and Scripting | 4 | 05-01-2008 12:21 PM |
| Script problem due to recursive directories Help please | robertmcol | Shell Programming and Scripting | 2 | 04-27-2008 08:00 PM |
| Function Problem and CoreDump | ZINGARO | Shell Programming and Scripting | 8 | 02-19-2008 06:37 PM |
| recursive function | bebop1111116 | High Level Programming | 1 | 10-30-2006 08:12 PM |
| PERL function problem | avadhani | Shell Programming and Scripting | 2 | 06-15-2005 05:18 AM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Problem with Recursive function
Hi all,
I have to move all the files in a tree directory structure to a single directory. Inorder to know which file is from which directory , i'll have to add the name of the directory to the file name. For this i wrote a recursive function which is as follows --------------------------------------------- datamover() { cd $1 #OLD_DIR=$2 for i in * do if [ -d $i ] then TMP_DIR=$i datamover $TMP_DIR echo $i else mv $i ../$1_$i if [ -f $1/ ] then echo some files still exist else cd .. rmdir $1 fi fi done } ---------------------------------------------------------------- When ever I execute the same on a directory structure as DirA --> DirB --> DirL -->fileN --> DirM-->fileO --->DirC --> DirP-->fileR --> DirQ-->fileS the program is giving the output as follows DirA -->DirB -->DirL_fileN -->DirM_fileO --->DirC --> DirP-->fileR --> DirQ-->fileS and the debug ouptut is as follows ------------------------------------------------------ + echo Dir Name is DirA Dir Name is DirA + MAIN_DIR=DirA + datamover DirA + cd DirA + '[' -d DirB ']' + TMP_DIR=DirB + datamover DirB + cd DirB + '[' -d DirL ']' + TMP_DIR=DirL + datamover DirL + cd DirL + '[' -d fileN ']' + mv fileN ../DirL_fileN + '[' -f DirL/ ']' + cd .. + rmdir DirL + echo fileN fileN + '[' -d DirM ']' + TMP_DIR=DirM + datamover DirM + cd DirM + '[' -d fileO ']' + mv fileO ../DirM_fileO + '[' -f DirM/ ']' + cd .. + rmdir DirM + echo fileO fileO + echo fileO fileO + '[' -d DirC ']' + mv DirC ../DirA_DirC mv: cannot stat `DirC': No such file or directory + '[' -f DirA/ ']' + cd .. + rmdir DirA rmdir: `DirA': No such file or directory -------------------------------------------------------------- Can anybody tell me wht's the problem with the code and how to correct it? the output i require in this scenario will be as DirA-->DirB_DirL_fileN -->DirB_DirM_fileO -->DirC_DirP_fileR -->DirC_DirQ_fileS Thanks in Advance |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|