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

Posted on 2011-10-28
Medium Priority
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
  • 2
LVL 18

Accepted Solution

Garry Glendown earned 2000 total points
ID: 37045043
try "cp -r $cpsource_IPAD/* $DestDir_IPAD" ...

Author Comment

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

Expert Comment

by:Garry Glendown
ID: 37045435
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

807 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