1

I have this directory structure:

c:\Parent\Child1\Images\folder1
c:\Parent\Child1\Images\folder2
c:\Parent\Child1\Images\folder3
c:\Parent\Child2\Images\folder1
c:\Parent\Child2\Images\folder2
c:\Parent\Child3\Images\folder1
c:\Parent\Child3\Images\folder2
c:\Parent\Child3\Images\folder3
c:\Parent\Child3\Images\folder4
etc.

Using the command line (Windows7), I would like to move each folder1, folder2, folder3 etc... up one level to its respective "childX" folder.

I will then remove the "Images" folders (I know how to do that).

1

You can use PowerShell! If you cd into the Parent folder and run this command, it will rearrange your folders as you desire.

dir -Directory | % {Push-Location $_.FullName; dir './Images' | % {Move-Item $_.FullName .}; del './Images'; Pop-Location}

Translation:

  • List all subfolders of the current directory
  • For each one:
    • Make it the current directory
    • List all items in the folder named Images
    • For each one:
      • Move it to the current folder (your numbered child folders)
    • Delete the now-empty Images folder
    • Restore the current directory to what it was before (your Parent)

If you would prefer that the command not delete the Images folders, you can remove the del './Images'; bit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.