LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   copy (https://www.linuxquestions.org/questions/programming-9/copy-560787/)

ovince 06-11-2007 02:03 AM

copy
 
hi,


I am trying to make a short script to copy files, whole tree structures ... This is how I started

###3 copyTree - cp tree structure: copyTree "*.dat" "*.txt" "C:/...."
Code:

function copyTree() {

if [ $# = 2 ]
    then
            find -depth -name "$1" -print0 | cpio --null -pvd $2
    elif [ $# = 3 ]
    then
            find -depth -name "$1" -name "$2" -print0 | cpio --null -pvd $2
    elif [ $# = 4 ]
    then
            find -depth -name "$1" -name "$2" -name "$3" -print0 | cpio --null -pvd $2       
fi               

}

It works when I use it like

copyTree "*.dat" "C:/...."

but not works when trying

copyTree "*.dat" "*.txt" "C:/...."

Why?

thanks

druuna 06-11-2007 03:31 AM

Hi,

If you want to use more then one -name option with find you need to add the -o (OR) option. I.e:

find -depth -name "$1" -o -name "$2" -print0

or

find -depth \( -name "$1" -o -name "$2" \) -print0

BTW: The first example will not always work, the second will.

Hope this helps.

ovince 06-11-2007 10:07 AM

I tried bot suggestion

Code:

###3 copyTree - cp tree structure:  copyTree "*.*" "C:/...."
function copyTree() {

if [ $# = 2 ]
    then
            find -depth -name "$1" -print0 | cpio --null -pvd $2
    elif [ $# = 3 ]
    then
            #find -depth \( -name "$1" -o -name "$2" \) -print0 | cpio --null -pvd $2
            find -depth -name "$1" -o -name "$2" -print0 | cpio --null -pvd $2
    elif [ $# = 4 ]
    then
            find -depth \( -name "$1" -o -name "$2" -o -name "$3" \) -print0 | cpio --null -pvd $2       
fi               

#find -depth -name "$1" -print0 | cpio --null -pvd $2

}

does not work...do you know why

druuna 06-11-2007 10:31 AM

Hi,

I see another typo/mistake in your script:

find -depth -name "$1" -o -name "$2" -print0 | cpio --null -pvd $2

Should be:

find -depth -name "$1" -o -name "$2" -print0 | cpio --null -pvd $3

And the find..cpio line below that should end with $4 instead of $2.

Hope this helps.

ovince 06-11-2007 10:42 AM

true ... you are very good observer


All times are GMT -5. The time now is 01:43 AM.