In C shell How do I copy all files and subdirectories in a directory using foreach loop?

Posted on 2011-10-28
Last Modified: 2013-12-26
Here is sample of of my script. I am using 2 seperate foreach loop because I am unsure how to copy both files and directories.

set cpsource_IPAD = "$SourceDir/$directory/ipad"

foreach file($cpsource_IPAD/*)
  cp $file "$DestDir_IPAD/$directory"

foreach directory($cpsource_IPAD/*)
  cp $directory "$DestDir_IPAD/$directory"
Question by:wademi
    LVL 17

    Accepted Solution

    try "cp -r $cpsource_IPAD/* $DestDir_IPAD" ...

    Author Comment

    Garry can you give me what the full foreach loop should look like. i am a novice to this
    LVL 17

    Expert Comment

    You don't need the foreach loop at all ... the "-r" option takes care of everything ... trying to code this in a shell script would require quite a bit of work, in order to take care of special cases, etc ...

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Unix / Linux grid computing 5 98
    ORA-01403: no data found 43 77
    while loop over for loop 7 69
    countEvens challenge 2 48
    In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
    Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now