0

I have to copy one mp3-file from it's subfolder to its parent folder and then rename it, e.g. NEW_originalfilename.mp3. There are lots of mp3s within each subfolder, but it doesn't matter which one is copied. Can be the first one.

E.g.

folder1/sub1/one.mp3
folder1/sub1/two.mp3
folder1/sub1/three.mp3
folder1/sub2/more1.mp3
folder1/sub2/more2.mp3
folder2/sub1/aaa.mp3
folder2/sub1/bbb.mp3
folder2/sub2/111.mp3
folder2/sub2/222.mp3
folder2/sub2/333.mp3

Result:

folder1/NEW_one.mp3
folder1/NEW_more1.mp3
folder2/NEW_aaa.mp3
folder1/NEW_111.mp3

Is there a batch windows solution?

colidyre
  • 4,170
  • 12
  • 37
  • 53
Letterman
  • 11
  • 3
  • 1
    @colidyre I surely answered myself similar questions, but your reference is tagged bash not batch-file. –  Aug 02 '18 at 12:44
  • What have you tried so far? – colidyre Aug 02 '18 at 12:53
  • @ECHO OFF SETLOCAL SET parent="C:\Users\Ubuntu\Desktop\TestMix" CD /d %parent% FOR /r %parent% %%d IN (*.mp3) DO XCOPY "%%d" %parent% ECHO Done. Press any key to terminate script. PAUSE >NUL – Letterman Aug 02 '18 at 13:10
  • This batch works fine, but the "XCOPY "%%d" %parent%" should be dynamic, so the files should be copied the refered subfolder and not to main parent folder – Letterman Aug 02 '18 at 13:14
  • @Letterman I think you need to Enable delayedexpension, use: `setlocal enabledelayedexpansion` and use "!" instead of "%" with your variable parent in the loop – S. Brottes Aug 02 '18 at 14:45
  • @Letterman: It could be a nice idea to move your code from the comments to the answer. I suggest to format it like I edited your folder descriptions (as code). – colidyre Aug 02 '18 at 15:23
  • Essentially what you are trying to do is move a file up one level. I think your terminology is a little off. The parent folder would be the folder the file is in. So the folder you wan to move it to would be the grandparent folder. Lot's of answers on SO that do that already. This question is probably almost asked weekly. I will find a few of the previous questions for you. Here is one from just a few days ago. https://stackoverflow.com/questions/51593698/batch-move-files-from-different-subfolder-up-one-level-respectively – Squashman Aug 02 '18 at 17:34

0 Answers0