Move all subfolder files to current folder

I'm sorry for asking this, I know it must have been asked a hundred times before. I tried the search and a google site search, and couldn't come up with anything similar.

What I want is:
To have a selection of folders
Run a script that moves ALL files in all subfolders to the current folder.

I.e. if I have this folder structure:

CurrentFolder
CurrentFolder/Subfolder1/AnotherFolder/01.jpg
CurrentFolder/Subfolder1/AnotherFolder/02.jpg
CurrentFolder/Subfolder1/03.jpg
CurrentFolder/Subfolder2/AnotherFolder/04.jpg
CurrentFolder/Subfolder3/AnotherFolder/05.jpg
CurrentFolder/Subfolder3/06.jpg

I want all those picture-files to be moved to the CurrentFolder
Also if all folders/subfolders inside of there could be deleted once the files are moved, that would be sweet.

Thanks for your time!

Not sure about a script but you can view the files in flat more, filter out all images and cut and paste them to the "current folder".

Yes, I want something like this, but as a button. To move out all files in all subfolders into the current folder.

Try this (not tested)

set flatview=MixedNoFolders
select all
copy here

Thanks, that works a bit of the way.

I now have:

set flatview=MixedNoFolders
select *(jpg|png|gif|bmp)
copy here

It works as far as copying the files go.
It asks me if I want to recreate the folder structure or place the files in the same folder.
Is there a way to silently/automatically select the Same Folder?

Hmm, what would I write to select only folders and delete them?

I did something here, but I'd still like to automatically select "SAME FOLDER" all the time.

set flatview=MixedNoFolders
select ALLFILES
copy here
set flatview=off
select ALLDIRS

This worked fine for me, I would

Add FLATVIEWCOPY=single to the Copy command.

My little DirFlatten tool might be useful. As well as moving the files it'll prefix each folder's files with a number so they stay grouped together (which may be good or bad, depending on what you're trying to do).

Thanks for the tip Jon! That worked flawlessly.
The DirFlatten tool also worked perfectly for what I wanted, but as it worked with the built-in tools it makes no sense in using a separate application. I will use it at work where I don't have my DOpus though :slight_smile:

Here's the "final" version of the script for anyone that might search for the same solution on how to move all files from a subfolder:

SET flatview=MixedNoFolders
SELECT ALLFILES
COPY MOVE HERE FLATVIEWCOPY=single
SET flatview=off
SELECT ALLDIRS

I also made it select all directories to make them easier to delete afterwards, but I didn't want to delete the folders themselves (if an error were to occur)

Hi @Jon or @Leo, I need a button that moves all files from sub-folders to the current folder.

I tried creating a button with @MNeMiC's suggested code:

SET flatview=MixedNoFolders
SELECT ALLFILES
COPY MOVE HERE FLATVIEWCOPY=single
SET flatview=off
SELECT ALLDIRS

Unfortunately, it doesn't seem to work properly (or as I expected it to).
After pressing the button, it simply displays all files in both the current folder...and sub-folders. Additionally it displays a renaming prompt on every file listed.

Looking at the date of the last post, it was 13 years ago. So maybe something changed that's causing this unexpected behavior.

I would appreciate any updated advice to accomplish such a task.

Command:Unpack folders with one step undoable - Buttons/Scripts - Directory Opus Resource Centre (dopus.com)
or

@dirsonly
Rename PATTERN="*" TO="{filepath|..}*" AUTORENAME RECURSE HERE
Delete
1 Like

Using the Select command to change which files another command uses is usually not the best approach. (It’s for changing what’s selected in the UI, while there are more direct ways to change which things commands work on.)

I would use scripting to build a list of files below the current folder and pass that to the Copy command. Then the button also doesn’t have to turn Flat View on and off, which can be time consuming and would be annoying if you wanted it to stay on.

(The default script includes an example of how to enumerate the files below a folder.)

Thanks @WKen! That code you posted (below the link) solves my problem.

At first I thought it glitched out when it immediately asked me to delete the sub-folders. But then I noticed the files were in the main-folder, right where I wanted them. It works so fast, it was initially surprising!

Won't that move things up one level, rather than flatten everything to the top level? There are better ways to do that, if so, and I am not sure that command is safe if you have nested folders with the same names like C:\...\Foo\Foo

See Move everything up in Quick buttons for directory organisation

I've been using it over the last hour, and it's worked without problems. I've been able to test both single and multi layered subfolders. After pressing the button, the files always appear in my active folder. And I've been double checking to make sure every file is moved correctly.

But just to be sure...I also tested your warning about identically named subfolders. And it worked in that scenario as well.

Of course, I will keep your warning in mind and use this feature sparingly. I'm not looking to do anything complicated - and in my use case, I'm double checking to make sure all files are accounted for.