0

I have a folder structure where in Folder1 there's subdirectories where each contains a subdirectory of the same name again. From that directory I want to move all subdirectories into Folder0. There's subdirectories of the same name, so their content shall be moved to the according subdirectory in Folder0.

For example:

Folder1/Fotos Teil 1 von 178/Fotos Teil 1 von 178/Photos/* shall be moved to Folder0/Photos/*

This is the structure

Folder0
├─Photos
├─Memories
├─Albums and Favorites
│
Folder1
├─Fotos Teil 1 von 178
│ └─Fotos Teil 1 von 178
│   ├─Photos
│   ├─Memories
│   └─Albums and Favorites
│
├─Fotos Teil 2 von 178
│ └─Fotos Teil 2 von 178
│   ├─Photos
│   ├─Memories
│   └─Albums and Favorites
╎
.
.
.
╎
├─Fotos Teil 178 von 178
│ └─Fotos Teil 178 von 178
│   ├─Photos
│   └─Albums and Favorites

I understand that this is probably a job for PowerShell. I have only worked with bash scripts, but this needs to be done in Windows.

3
  • 1
    so you want all the files in the deeper photos dirs moved to the top level photos dir? and the same to be done for the other dirs at the deeper level? Commented Oct 14, 2019 at 8:47
  • Yes, that's it. Move all the folders within "Folder1/foo/foo/" to "Folder0". If they already exist (like 'Photos'), move the containing files. Commented Oct 14, 2019 at 8:53
  • when you use Get-ChildItem to load a directory info object, you can use the .Parent property to find the parent dir. you can do .Parent.Parent to get the two parent dirs ... and then compare them. if they are the same, you have one of your double-named dirs. ///// however, a simpler way may be to just grab any dir with the desired name that is NOT at the top level. Commented Oct 14, 2019 at 9:01

1 Answer 1

2

Here a short snippet (not tested!).
Might that one helps you for the logic and how to do this in PowerShell.

$Source = '.\Folder1'
$Destination = '.\Folder0'

foreach ($Folder in (Get-ChildItem -Path ($Source + '\*\*\'))) #For each folder -> Photos / Memories / Albums and Favorites
{
    foreach ($Item in (Get-ChildItem -Path $Folder.FullName)) #Get all items
    {
        Move-Item -Path $Item.FullName -Destination ($Destination + '\' + $Folder.Name) #Move the items
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.