title: copy file from resource to disk keeping folder structure (platform independant)
body: <p><strong>Problem:</strong></p>
  
  <p>How do I copy resource files, while preserving file names, to the disk in a platform independent way?</p>
  
  <p><strong>Example and Explanation:</strong></p>
  
  <p>I have files in my Resource File (<a href="http://doc.qt.io/qt-5/resources.html" rel="nofollow noreferrer">.qrc file</a>) e.g.:</p>
  
  <pre><code>:/student/stud_temp              (student/template.txt)
  :/student/examples/stud_exOne    (student/examples/student_example1.txt)
  :/student/examples/stud_exTwo    (student/examples/student_example2.txt)
  
  :/lecturer/lec_temp              (lecturer/template.txt)
  :/lecturer/lec_ex                (lecturer/lecturer_example.txt)
  :/lecturer/data/lec_data         (lecturer/data/data_file.dat)
  </code></pre>
  
  <p>I would like to copy these files on to the disk, for sake of the example, preserve the file structure.</p>
  
  <p>So the resulting folder structure should be something like this (unix system):</p>
  
  <pre><code>$ ls $PWD
  student lecturer
  
  $ ls $PWD/student
  template.txt
  examples
  
  $ ls $PWD/lecturer
  template.txt
  lecturer_example.txt
  data
  </code></pre>
  
  <p>There is a method suggested <a href="https://stackoverflow.com/questions/10724899/how-to-copy-qrc-resource-file-into-filesystem">here</a> to copy to filesystem, as shown below, but the file name needs to be specified. However this <em>should</em> be automated to get the resource's original filename.</p>
  
  <p>Currently I need to do the following to replicate the folder structure:</p>
  
  <pre><code>QDir::mkpath("../student");    
  QFile::copy(":/student/template.txt", "../student/template.txt")
  </code></pre>
  
  <p>However I cannot believe that this is the best way.</p>
  
  <p><em>Also, this method is platform dependant, due to the directory separators (trivial problem though).</em></p>
  
  <p>Are there any better ways to achieve this?</p>