Move files from multiple folders all into parent directory with command prompt

8

2

I have multiple .rar files in multiple folders like this:

C:\Docs\Folder1\rarfile1-1.rar
C:\Docs\Folder1\rarfile1-2.rar
C:\Docs\Folder1\rarfile1-3.rar  

C:\Docs\Folder2\rarfile2-1.rar
C:\Docs\Folder2\rarfile2-2.rar
C:\Docs\Folder2\rarfile2-3.rar  

C:\Docs\Folder3\rarfile3-1.rar
C:\Docs\Folder3\rarfile3-2.rar
C:\Docs\Folder3\rarfile3-3.rar  

I want to move all of the .rar files to the parent directory 'C:\Docs'. I have a lot more than 3 folders, so I was thinking of making a batch file or something. What would be the commands to do this?
Thanks

Nick

Posted 2010-08-25T14:47:49.543

Reputation: 89

I searched for a similar issue and I found this answer to be useful.

– lalthomas – 2016-07-14T14:50:35.657

Answers

14

I've just made a commandline application that does exactly this (plus shows some stats) and searched to see if anybody was trying to do it so I could share it and save someone from having to figure it out.

It was a lot of fun to write. Requires .NET 3.5, works from the commandline, call with -h or no parameter for usage.

MoveFilesUpFromSubfolders
(source code)

Feedback a plus! :)

Oh, and screenshot of how it looks:

                               

Camilo Martin

Posted 2010-08-25T14:47:49.543

Reputation: 2 308

Great work! +1 and 50 rep. I know this is 4.5 years old, but this was very useful for me because I downloaded 90+ files that went in 90+ folders. This helped me to put all the files in its parent folder. – None – 2015-07-12T20:40:15.877

The only critique I have is that when I tried to use this, an error about a problem with the folder kept coming up, and it didn't state why. Only by using the -t command, I was able to determine why there was a problem with the folder (because it was named with 250+ characters). This is easily circumvented by highlighting all the folders and renaming one of them (then the rest will be appended with a number). – None – 2015-07-12T20:43:05.267

@edmastermind29 I'm super happy to know that such an old code of mine has been of use to someone still. Believe it or not, the source code archive was taken off of mediafire for being auto-flagged as copyright infringement (which is pretty absurd, considering there's no video or audio but just text there), and I'm clueless about how I made this. If it's of any use, at this point I'd write a bash one-liner to deal with a problem like this, something like mv dir/sub/* dir; rmdir dir/sub in a loop. – Camilo Martin – 2015-07-13T20:54:00.967

@CamiloMartin This saved me big time. I was working on a project with someone and he sent me a zip file with 2219 folders in it each with 1 image. Thank You so much for this program it helped me big time. – Belldandu – 2015-11-07T22:07:16.607

3+1 Writing a program to solve someone's problem. That's commitment! – Li-aung Yip – 2012-03-17T09:14:01.393

1@Li-aungYip Thank you very much for the compliment! Also, due to circumstances, I no longer have the hard drive where I used to code in the time I made this (having lost this and many other things), so I'm quite happy to see it here and have downloaded it now (kudos for Mediafire for storing it for so long with few downloads, and I'm lucky I didn't store it in Megaupload!). So if you put it in perspective, the more you give the more you receive :) – Camilo Martin – 2012-03-17T10:26:36.843

7

Give this a try:

for /d %f in (docs\*) do (
pushd %f
move .\*.* ..
popd
)

BillP3rd

Posted 2010-08-25T14:47:49.543

Reputation: 5 353

Here's a one liner that works for all folders in the current working directory for /d %f in ("%cd%"\*) do move "%f\*.*" "%cd%" – Sean Bannister – 2014-10-09T03:23:29.027

Can you explain this a little more? – Nick – 2010-08-25T15:16:03.363

@Nick: For all folders in docs, enter folder. Move all files from current folder to parent folder. Return to parent folder. – Hello71 – 2010-08-25T19:48:57.200

The pushd and popd isn't really necessary. cd would work just fine. – Hello71 – 2010-08-25T19:49:25.937

As explained by Hello71. Also, could be done with a single line: for /d %f in (docs\\*) do move %f\\*.* docs – BillP3rd – 2010-08-25T20:45:13.447

NB. Neither the original above nor the one-liner will deal properly with duplicate file names. – BillP3rd – 2010-08-25T20:47:04.630

5

Well, the answer for your question is very simple. Its not a script but it will do.

I assumed that you are running windows.

  • Place youself in C:\Docs directory
  • Press F3 (search)
  • Search for *.rar
  • Press Crtl+A
  • Press Ctrl+X
  • Close search window and one again go to C:\Dosc in explorer
  • Paste cutted files by pressing CTRL+V.

integratorIT

Posted 2010-08-25T14:47:49.543

Reputation: 727

+1 for nice and simple workaround without any 3rd party or scripts. – Syakur Rahman – 2014-10-14T01:51:56.570

>

  • 1 best and fastest method A+++
  • < – Sickest – 2017-09-06T05:48:04.133

    3

    Suction worked for me on this issue.

    Suction is a free, portable app that will help sort out messy folders in no time at all.

    Suction works by consolidating parent directories. For example, if your images directory is full of unnecessary folders, drag the folder into the Suction interface, and it will do away with the folders, leaving you just with the files. This is also useful for people who download a lot of stuff.

    Raystafarian

    Posted 2010-08-25T14:47:49.543

    Reputation: 20 384

    0

    This should work:

    move C:\Docs\*\* C:\Docs
    

    Hello71

    Posted 2010-08-25T14:47:49.543

    Reputation: 7 636

    2I get the error: the filename, directory name, or volume label syntax is incorrect. – Nick – 2010-08-25T15:07:07.850

    The ** did not work – Nick – 2010-08-25T15:14:15.047

    You need to make sure you put the \\ in, and that it's not being escaped by your text editor. – Hello71 – 2010-08-25T19:48:12.973

    Issuing this command from a CMD prompt (in Windows 7) generates the error noted by Nick. – BillP3rd – 2010-08-25T20:41:20.960

    This won't work. * does not properly work for folders. Gotta break out the third party programs like Total Commander. – surfasb – 2011-02-15T12:52:04.997

    0

    Examples of copying or moving files from sub-directories to a single directory

    for /f "tokens=*" %a in ('dir "C:\Temp\Epub*.epub" /s /b') do copy /y "%a" C:\Temp\epub.

    for /f "tokens=*" %a in ('dir "C:\Temp\Epub*.epub" /s /b') do move /y "%a" C:\Temp\epub

    the "tokens=* is to capture paths with special characters

    user340812

    Posted 2010-08-25T14:47:49.543

    Reputation: 1