Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have files containing in

C:\foldername1\Files\soandso1.mkv C:\foldername2\Files\soandso2.mp4 C:\foldername3\Files\soandso3.avi

I want to move the .mkv, .mp4, and .avi back to it's parent folder, which is foldername1, 2, 3.

foldername will be different for each soandso file is in. Basically, I want to get rid of the "Files" folder and have the media files placed in foldername1, 2, and 3.

Is there a batch command for this?

share|improve this question
    
So foldername1\Files only contains MKVs, foldername2\Files has only MP4s and foldername3\Files has only AVIs? –  Karan Feb 2 '13 at 1:48
    
No, it could be random. "foldername" can go up to "foldername50" which contains a "Files" folder. Inside "Files" contains either a .mkv, .avi, or .mp4. –  Roger Feb 2 '13 at 2:04
    
Also, it would be nice if I can include a command that deletes the "Files" folder after the move. –  Roger Feb 2 '13 at 2:05
    
Since this looks to be a one-time deal, any reason why a simple search + sort by extension + cut/paste won't do? Also, which version of Windows? –  Karan Feb 2 '13 at 2:11
    
because there is multiple "foldername", which means I have to go into each of them, go into "Files", cut and paste it to the parent "foldername"? Is there a search sort and cut paste technique I don't know about? I'm pretty new to these sort of stuff. –  Roger Feb 2 '13 at 2:13

1 Answer 1

up vote 1 down vote accepted

Something I put together quickly; no time to test extensively right now:

@echo off
for /f "delims=" %%d in ('dir /b/ad-s-h') do (
    if exist "%%d\Files" (
        pushd "%%d\Files"
        if exist *.avi move *.avi ..
        if exist *.mkv move *.mkv ..
        if exist *.mp4 move *.mp4 ..
        popd
        rd "%%d\Files"
    )
)

If you run it in C:\, it will look at each top-level folder on the drive and if it contains a Files sub-folder, it will move any AVI/MKV/MP4 files found up one level (i.e. to the top-level folder), then delete the Files sub-folder.

If any other files exist in Files the folder will not be deleted. You can use rd /s /q if you want to forcibly delete. Also, move will prompt you each time to overwrite duplicates (if any), which can be done automatically by using move /y instead.

share|improve this answer
    
I am using windows 7, how do i execute this command? –  Roger Feb 2 '13 at 2:40
    
Copy+paste in Notepad, save as something like "D:\Test.bat" (with the quotes!), then open a command prompt window, navigate to C:\, D:\ or whichever drive you want to run it on, and type D:\Test.bat. I advise you to copy a few of the folders to another drive and test the batch file on them first, before letting it loose on your entire collection (although it won't delete any files if saved as posted above). –  Karan Feb 2 '13 at 2:43
    
thank you! i'll post back and let you know. –  Roger Feb 2 '13 at 3:24
    
Wow! Tested it and it works. Thanks Karan! You just saved me hours of work with this. –  Roger Feb 2 '13 at 3:29
    
Hmm... executing on the actual drive with the media didn't complete do the work. Some files didn't move and some "Files" folder did not delete by itself. Maybe it was too large of a batch to execute all commands, but it got most of the job done. –  Roger Feb 2 '13 at 3:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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