in reply to Copying files from one directory to another with different subdir

What code do you already have and how does it fail to do what you want?

Most likely, your code will be using File::Copy or File::Copy::Recursive.

Also, have you considered simply using:

system(qq{cp -rp '$source_dir' '$target_dir'}) == 0 or die "$! / $?";

... or on Windows

system(qq{xcopy /v /q /i /e /s "$source_dir" "$target_dir"}) == 0 or die "$! / $?";

Replies are listed 'Best First'.
Re^2: Copying files from one directory to another with different subdir
by PiyaPerl (Acolyte) on Sep 19, 2016 at 12:48 UTC
    But how do i get the subdir recursively.so that the file from dir A/B goes to C/B and so on also for F/B goes to G/B

      That's what the cp -r does. Did you try one of those commands and it did not work? What did happen?

      But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)

      Maybe you can show some examples of what you have as source directory structure and target directory structure and how both source and target are specified. Then we can better advise you on the approach to take.

        sure... so the source directory is like :
        /proj/tool/STAGE/<ENV>/<CLIENT>/*.xml and the target dir is like:
        /proj/tool/PROD/<ENV>/<CLIENT> Where in both cases the <ENV> can be something like: Env A,Env B and so on and Client can be Client A and Client B and so on. but ideally the script should be able to copy files from source to target. something like :
        cp /proj/tool/STAGE/EnvA/ClientA/*.xml /proj/tool/PROD/EnvA/ClientA
        cp /proj/tool/STAGE/EnvA/ClientB/*.xml /proj/tool/PROD/EnvA/ClientB
        cp /proj/tool/STAGE/EnvB/ClientC/*.xml /proj/tool/PROD/EnvB/ClientC
        Let me know if more information is needed.