Reputation: 27
With this code all files in each subdirectory will move one level up, and not only the files from last subdirectory. Also the files in the folder where the bat-file is placed, and the bat-file itself, moves one level up. And this is not the intention. I want only move the files from the last subdirectory.
For info, the last subdirectories from each folder have also a different name.
for /r %%x in (*.*) do move "%%x" "%%x"/../..
Later if this should work I would also delete the empty subdirectories. But the biggest problem is now to move the files one level up.
As an example for one folder:
I have:
D:\FILMS
------\Bikini Spring Break
-------------\EPCSKGCWZCXDJEH
---------------------------\DVD
------------------------------\P2HBSB5.iso
------------------------------\0001.jpg
------------------------------\lees.txt
I want:
D:\FILMS
------\Bikini Spring Break
-------------\EPCSKGCWZCXDJEH
---------------------------\P2HBSB5.iso
---------------------------\0001.jpg
---------------------------\lees.txt
Finally, at the end it's the intention to get something like this:
D:\FILMS\Bikini Spring Break\P2HBSB5.iso --> and other files (".jpg", etc)
D:\FILMS\Breaking the Girls (20122013) PAL\P2HBTG5.iso
D:\FILMS\De marathon\MW93JLNPNH8PLLK.iso
Here all subdirectories are deleted and all files are in his own movie-named folder.
Because all movie folders haven't the same amount of subdirectories I think the only solution is to move all files from the last subirectory one level up and see which folders still have subdirectories, and place these ones in a seperate folder, so I will be able to execute the code till all subdirectories are deleted.
Upvotes: 0
Views: 2764
Reputation: 41267
Test this on some sample folders.
I'm clarifying here that it doesn't move files one level, but moves all files under a movie folder into the same movie folder.
IE: All files under d:\films\Bikini Spring Break
including subdirectories will be moved into d:\films\Bikini Spring Break\
d:\films\Bikini Spring Break\P2HBSB5.iso
d:\films\Bikini Spring Break\0001.jpg
d:\films\Bikini Spring Break\lees.txt
It will prompt if any files have the same name.
it should move all the files under each movie folder, into the appropriate movie folder, and if those extra folders are empty it will also remove them.
@echo off
pushd "d:\films"
for /f "delims=" %%a in (' dir /ad /b ') do (
pushd "%%a"
for /r %%b in (*) do move /-y "%%b" .
for /f "delims=" %%c in (' dir /b /s /ad ^|sort /r') do rd "%%c" 2>nul
popd
)
popd
Upvotes: 1