0

I'm trying to move all files that are in a level-three sub-directory structure up one level.

A:\mozartBilder\Box 03 - Divertimenti, Serenades\CD02\img\folder.jpg

I basically want to get rid of the img sub-directory, but keep its contents one level above.

These are of my 180 cd collection of Mozart's Works. There are 180 cds, 17 Box Sets, each box containing ~11 cds. Each picture was placed in this exact structure:

A:\mozartBilder\Box*number1-17\CD*1-11\img\folder.jpg

What I want to achive is that the folder.jpg gets moved up one directory.

So to go from

A:\mozartBilder\Box 03 - Divertimenti, Serenades\CD02\img\folder.jpg

to

A:\mozartBilder\Box 03 - Divertimenti, Serenades\CD02\folder.jpg

I've searched on SuperUser and found people with similar questions, however none of the provided solutions worked for me.

For this code:

A:\mozartBilder>for /r %i in ("img\folder.jpg") do move %i %~pi..

I get this error:

A:\mozartBilder>move A:\mozartBilder\Box 02 - Serenades, Dances, Marches\CD03\"img\folder.jpg" \mozartBilder\Box 02 - Serenades, Dances, Marches\CD03\"img\.. The syntax of the command is incorrect.

2
  • Are there any folder.jpg files in the 'box-level" folders or does the following PowerShell list only the files you want to move: gci A:\mozartBilder folder.jpg -recurse | select fullname Aug 12, 2019 at 22:14
  • No, in "box-level" folder there are no folder.jpg files. they are located in ..\img\ I ran this powershell command and it provides a list of all the files located in ..\img. But now, how can I move them so they all sit one level above? A:\mozartBilder\BOX***\CD01\img\folder.jpg --> A:\mozartBilder\BOX***\CD01\folder.jpg
    – Phil
    Aug 12, 2019 at 23:18

2 Answers 2

1

To move folder.jpg up one level but keep the \img folder:

gci A:\mozartBilder folder.jpg -recurse |
   move-item -Destination {$_.Directory.Parent.FullName}

To move the file up one level & delete the \img folder (assuming it's empty):

gci A:\mozartBilder folder.jpg -recurse |
   move-item -Destination {$_.Directory.Parent.FullName}
gci A:\mozartBilder -recurse |
   ?{$_.PSChildName -match 'img'} | remove-item

Trying to combine move-item & remove-item in a single foreach-object resulted in error messages even though the file was moved & directory deleted, so I went with the above approach.

3
  • thanks, I tried it but I get an error move-item : Cannot find path 'A:\folder.jpg' because it does not exist. At line:3 char:8 + move-item $_ $_.Directory.Parent + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (A:\folder.jpg:String) [Move-Item], ItemNotFoundException + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.MoveItemCommand
    – Phil
    Aug 13, 2019 at 8:29
  • the command gci A:\mozartBilder folder.jpg -recurse | select fullname does give a full list of all items. the structure looks exactly like so: link
    – Phil
    Aug 13, 2019 at 8:36
  • 1
    Sorry about that. It worked in limited testing. Built a similar directory structure & got the same error. Answer now edited with updated code that should work. Aug 13, 2019 at 15:53
0

A nice, easy, way with GUI.

Download Double Commander; it's a twin pane file manager which is free, even for commercial use, and cross platform. You may soon find that you never visit the command line again.

The twin panes are great for move/copy/archive/unarchive/compare operations, not to mention FTP, file/directory compare, multi-file/directory rename, file search by name/contents (with wildcards/regex), etc.

You have two options here:

  • Navigate to A:\mozartBilder\Box 03 - Divertimenti, Serenades\CD02\img\ in the left pane and A:\mozartBilder\Box 03 - Divertimenti, Serenades\CD02\ in the right pane
    • select all files in the source directory by using the keypad plus key, or by hitting Ctrl-A
    • press F6 to move all files and enter to select the destination

OR

  • Navigate to A:\mozartBilder\Box 03 - Divertimenti, Serenades\CD02\img\ in the left pane
    • select all files in the source directory by using the keypad plus key, or by hitting Ctrl-A
    • press F6 to move all files and type .. (parent directory) for the destination.

Quod erat demonstrandum :-)

Since no answer is complete without an image ...

enter image description here

Please let us know how it works out (and take a good look at all of DC's features; I only scratched the surface above)

4
  • 1
    so there are 180 ...\img\folder.jpg items which have to be moved. Following your instructions just takes care of one of them. I want to move them up one level by an automated command, so that I don't have to repeat the task myself 180 times.
    – Phil
    Aug 13, 2019 at 8:59
  • Oops! Hmmm, perhaps the "multi rename" command? Failing that, a simple Python script. You might want to consider asking us for an app on software recommendations
    – Mawg
    Aug 13, 2019 at 9:06
  • 1
    I don't want to rename folder.jpg, I want to move them one level up the directory-hierarchy
    – Phil
    Aug 13, 2019 at 9:12
  • I was hoping (I haven't tried this), that you could give a path + file name as the search text & replace text.
    – Mawg
    Aug 13, 2019 at 10:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .