title: How do I copy all files of a nested directory structure into one new directory with adding the recursive path to the file name?
body: <p>maybe some could give me some help with my issue: students upload their java codes via MS Teams assignments that I want to review (and compare with each other) locally.</p>
  <p>It is possible for me as a teacher to do a bulk download of all submissions. Extracting the zip reveals the following structure:</p>
  <ul>
  <li>root
  <ul>
  <li>student1name
  <ul>
  <li>project1
  <ul>
  <li>version1
  <ul>
  <li>file1.java</li>
  <li>maybe also other files like file1.class, myfirstcodepastedinword.doc, screenshotofcode.jpg...</li>
  </ul>
  </li>
  <li>version2 //optional
  <ul>
  <li>file1.java</li>
  <li>subdir // optional
  <ul>
  <li>otherfile.class</li>
  <li>nextsubdir
  <ul>
  <li>lastfile.txt
  ...</li>
  </ul>
  </li>
  </ul>
  </li>
  </ul>
  </li>
  </ul>
  </li>
  <li>project2
  <ul>
  <li>version1
  ...</li>
  </ul>
  </li>
  </ul>
  </li>
  <li>student2name
  <ul>
  <li>project1
  <ul>
  <li>version1
  <ul>
  <li>nextClass.java
  .. and so on...</li>
  </ul>
  </li>
  </ul>
  </li>
  </ul>
  </li>
  </ul>
  </li>
  </ul>
  <p>What I am looking for is a litte batch that collects all project-sepecific submissions together in one directory (for being able to do simple comparisons).
  For identification, the student's name and all leading subdirectories must be added to the new file name.</p>
  <p>So, after calling &quot;collectSubmissions.bat&quot;, the result should be a new dir called &quot;Submissions&quot; containing all files as follows:</p>
  <ul>
  <li>project1
  <ul>
  <li>student1name-version1-file1.java</li>
  <li>student1name-version1-file1.class (could by omitted, but too much effort, I will simply ignore this manually)</li>
  <li>student1name-version1-myfirstcodeinword.doc</li>
  <li>student1name-version1-screenshotofcode.jpg</li>
  <li>student1name-version2-file1.java</li>
  <li>student1name-version2-subdir-otherfile1.class</li>
  <li>student1name-version2-subdir-nextsubdir-lastfile.txt</li>
  <li>...</li>
  <li>student2name-version1-file1.java</li>
  <li>...</li>
  </ul>
  </li>
  <li>project2
  <ul>
  <li>student1name-version1-nextClass.java
  ....</li>
  </ul>
  </li>
  </ul>
  <p>I did some research and tried different approaches (starting <a href="https://stackoverflow.com/questions/246559/how-can-i-recursively-copy-files-of-a-specific-pattern-into-a-single-flat-folder">How can I recursively copy files of a specific pattern into a single flat folder on Windows?</a>) and found one pretty close to my needs here:</p>
  <p><a href="https://stackoverflow.com/questions/57603775/how-do-i-copy-files-with-adding-folder-name-to-destination-file-name">How do I copy files with adding folder name to destination file name?</a></p>
  <p>But only the closest parent directory name is used here. But in my case, there can be multiple nested folders, so I am hoping that someone could give me some advice how to do that.</p>
  <p>Thank you so much in advance for your help!</p>