title: How do I check whether a file is a directory, do the same for its sub directories and their contents recursively and copy them to another location
body: <p>I am new to programming and I have a problem. I need to check whether a file is a directory or not, if yes need to do the following :</p>
  <ol>
  <li>check whether it has contents. Contents can be  sub-directories or just files.</li>
  <li>need to do the check recursively for every file inside the parent directory</li>
  <li>copy each directory and file to another location, preserving the directory structure.</li>
  <li>Also need to copy the database entries corresponding to every file/directory to another table<br />
  along with the actual files</li>
  </ol>