Copy multiple folders with files without subfolders

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
rockberto
Junior Member
Junior Member
Posts: 7
Joined: 2024-07-16, 08:42 UTC

Copy multiple folders with files without subfolders

Post by *rockberto »

Hi to all.
is there a way to copy files (even if they are contained in subfolders) without the folder structure, manteining each parent folder?
For example I have a folder called "DEEP PURPLE IN ROCK" that contains a subfolder called "MEDIA" and inside the subfolder there are files like image.cue and image.flac
I would like to copy only the folder "DEEP PURPLE IN ROCK" and the two files without maintaining the structure, basically I would like the files to go into the main folder and the "MEDIA" folder to disappear.
The solution I use is a bit long: first I compress all the folders with winrar and then I unzip them with some parameters that remove the subfolders and keep only the files. But it becomes a very long procedure when there are many folders and you have to do it in two steps. It would be more useful to do it in one step.
Thanks in advance
User avatar
petermad
Power Member
Power Member
Posts: 16001
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Copy multiple folders with files without subfolders

Post by *petermad »

In the copy dialog set the value in "Only files of this type" to:

Code: Select all

*|MEDIA\
License #524 (1994)
Danish Total Commander Translator
TC 11.51 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1391a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
rockberto
Junior Member
Junior Member
Posts: 7
Joined: 2024-07-16, 08:42 UTC

Re: Copy multiple folders with files without subfolders

Post by *rockberto »

the problem is that I have many parent folders to copy and the subfolders inside them have different names. I would like to copy with a single command all the parent folders with the relative files inside but without the structure of the subfolders.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50390
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Copy multiple folders with files without subfolders

Post by *ghisler(Author) »

You can use branch view to view just the file names, then when you copy with F5 you can choose to copy the files without their relative paths.
You will still need to create the subfolders to which you want to copy. You can do this by placing the cursor on a folder, then press Shift+F7 to create a folder with the same name in the target panel.

To use branch view for a single folder, do the following:
1. Select the folder(s)
2. Press Ctrl+Shift+B
3. Select the files, e.g. with Ctrl+A
4. Press F5 to copy and uncheck the option to keep relative paths
Author of Total Commander
https://www.ghisler.com
User avatar
petermad
Power Member
Power Member
Posts: 16001
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Copy multiple folders with files without subfolders

Post by *petermad »

2rockberto
the problem is that I have many parent folders to copy and the subfolders inside them have different names. I would like to copy with a single command all the parent folders with the relative files inside but without the structure of the subfolders.
If it is a limited number of diffrent subfolder names, you could still use the approach:

For example set "Only files of this type" to:

Code: Select all

*|MEDIA\ foldername1\ foldername2\ foldername3\ foldername4\
Otherwise you could use Find files and set "Search in subdirectories" to 1 level(s) - Then Feed to listbox, mark the file but not the folders - and copy with the "Keep relative paths (relative to the current directory)" enabled - You will then get your folders copied without subfolders - but they will be placed in a folder with the name of the folder you are in when you start the Search - so you have to move the subfolders from the that folder to your final destination - so it is a 3 stage operation - but still much easier than your archive packing approach.

You can avoid the drive letter in the folder name by placing RelativePathCopy=8 in the [Configuration] section of your wincmd.ini file
License #524 (1994)
Danish Total Commander Translator
TC 11.51 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1391a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
Fla$her
Power Member
Power Member
Posts: 2982
Joined: 2020-01-18, 04:03 UTC

Re: Copy multiple folders with files without subfolders

Post by *Fla$her »

2rockberto
Try this *.bat for a button or em_:

Code: Select all

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::    Purpose: Copy selected dirs with found files without structure
:: Parameters: %F <target dir\> <file masks>
::    Example: %F "%T" "file name.ext" name.txt *.jpg *.pdf
::  Condition: empty start path in a button or custom command
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off&if "%1" lss "3" exit
set n=&setlocal enabledelayedexpansion
for /f tokens^=2* %%o in ('echo %*') do set "p=%%p"
for /f tokens^=*  %%d in ('^<%1 more') do (
   if exist "%%d\" (
      pushd "%%d"
      for /f tokens^=* %%# in ('dir/a-d/b/s !p!') do (
         call:loop "%~2%%~d%%~n#" %%~x#
         echo f|>nul xcopy /chikqry "%%#" "!f!"
      )
      popd
   )
)
exit

:loop
set "f=%~1!n!%2"
if exist "!f!" (
   set /a c+=1&set n=_!c!
   goto loop
) else set c=&set n=
Overquoting is evil! 👎
rockberto
Junior Member
Junior Member
Posts: 7
Joined: 2024-07-16, 08:42 UTC

Re: Copy multiple folders with files without subfolders

Post by *rockberto »

thanks for the reply.
I copied the code into a .bat file, the difficulty now is how to use it inside total commander! :(
Fla$her
Power Member
Power Member
Posts: 2982
Joined: 2020-01-18, 04:03 UTC

Re: Copy multiple folders with files without subfolders

Post by *Fla$her »

rockberto wrote: 2024-09-07, 21:56 UTC the difficulty now is how to use it inside total commander! :(
Nothing difficult: drag to the button bar and follow the description.
Overquoting is evil! 👎
Post Reply