Copying files from list
Moderators: petermad, Stefan2, Hacker
Copying files from list
I have a file with a list with many filenames (only names, not paths) that need to be copied.
Files from the list are scattered among many subfolders together with many other files. Filenames are unique, if that matters. I need to copy them and to keep the existing folder structure.
I thought to use branch view or 'feed to listbox' from findfiles with 'get selection from file', but those lists don't support loading selections.
Is there a way in TC to perform this, or should i script it?
Files from the list are scattered among many subfolders together with many other files. Filenames are unique, if that matters. I need to copy them and to keep the existing folder structure.
I thought to use branch view or 'feed to listbox' from findfiles with 'get selection from file', but those lists don't support loading selections.
Is there a way in TC to perform this, or should i script it?
Re: Copying files from list
Relative to what? The path of the active panel?keep the existing folder structure
Depends on the size of the list. If it's small, you can copy it to the clipboard (em_ListToClip: %Comspec% /q/c clip<C:\path\to\list.txt) and do something like cm_Copy /B1SGRW="%$CLIPNAME0%" (/T="%T" in the second field). But it's just an idea, I haven't tried it.Is there a way in TC to perform this, or should i script it?
Overquoting is evil! 👎
Re: Copying files from list
If the file is in F:\upperfolder\starthere\files\morefiles\file.ext and the destination is T:\copyhere\, my source panel is at F:\upperfolder\starthere, then file should be copied to T:\copyhere\files\morefiles\file.ext
Another file is F:\upperfolder\starthere\files_5\evenmorefiles\af\file2.ext then copy to T:\copyhere\files_5\evenmorefiles\af\file2.ext
I haven't tried it either, but AFAI understand it, it will look for the file only in the source folder, not subfolders. I have only filenames in the list, not paths.Fla$her wrote: 2026-05-15, 19:55 UTC Depends on the size of the list. If it's small, you can copy it to the clipboard (em_ListToClip: %Comspec% /q/c clip<C:\path\to\list.txt) and do something like cm_Copy /B1SGRW="%$CLIPNAME0%" (/T="%T" in the second field). But it's just an idea, I haven't tried it.
Re: Copying files from list
Yes they do. But normally you have to include path (search results) or part of the path (branch view). That is, unless you use wildcards. So transform your list to this format:solid wrote: 2026-05-15, 17:42 UTC I have a file with a list with many filenames (only names, not paths) that need to be copied.
Files from the list are scattered among many subfolders together with many other files. Filenames are unique, if that matters. I need to copy them and to keep the existing folder structure.
I thought to use branch view or 'feed to listbox' from findfiles with 'get selection from file', but those lists don't support loading selections.
Code: Select all
*"file 1.txt"
*"file 2.exe"
*"file 3"
...
Another way is to utilize the search duplicate files function. For that you need actual files with the filenames. If you don't have files with these filenames, you can create them.
Suppose you have 1000 names in your list. You can create 1000 files without content by pressing Shift+F4 and using this template:
Code: Select all
<1-1000>[C]Once you have all the files, open search.
In the "Search in" field, enter your target folder and the folder with created empty files, separated by ";".
Use the Advanced tab to search for duplicates, and search for same name only.
Start the search and feed the result to the listbox.
Press Num + (the Select duplicate files dialog pops up) and use the appropriate options to select only the files you want to copy.
When using this method you can only copy with full path, so you will have to more work to get only the part of the path you want.
Re: Copying files from list
It will filter the files you specify. So you copy a whole structure and you filter only the filenames you want. You can use the normal copy function and specify your filenames in the "Only file of this type" field. But the amount of filenames you can enter here is of course limited.solid wrote: 2026-05-15, 21:22 UTCI haven't tried it either, but AFAI understand it, it will look for the file only in the source folder, not subfolders. I have only filenames in the list, not paths.Fla$her wrote: 2026-05-15, 19:55 UTC Depends on the size of the list. If it's small, you can copy it to the clipboard (em_ListToClip: %Comspec% /q/c clip<C:\path\to\list.txt) and do something like cm_Copy /B1SGRW="%$CLIPNAME0%" (/T="%T" in the second field). But it's just an idea, I haven't tried it.
Re: Copying files from list
If you select everything with Ctrl+A, it will also copy from the subfolders.solid wrote: 2026-05-15, 21:22 UTCI haven't tried it either, but AFAI understand it, it will look for the file only in the source folder, not subfolders.
In this case, /R will no longer be needed, since it is only required after Ctrl+B.
Overquoting is evil! 👎
Re: Copying files from list
Thanks a lot for this hint. It is exactly what I needed.white wrote: 2026-05-15, 21:48 UTC Yes they do. But normally you have to include path (search results) or part of the path (branch view). That is, unless you use wildcards. So transform your list to this format:And then use the LOADSELECTION command to load the selection.Code: Select all
*"file 1.txt" *"file 2.exe" *"file 3" ...
Is this syntax actually documented somewhere?
Thanks to you too.Fla$her wrote: 2026-05-15, 22:29 UTC If you select everything with Ctrl+A, it will also copy from the subfolders.
In this case, /R will no longer be needed, since it is only required after Ctrl+B.
@white already explained how it works, but I think I will stick to his other solution.
Problem solved!
Re: Copying files from list
I don't think so, but I did mention this syntax on the forum before.
Re: Copying files from list
I still want to know how many characters are in the list?
Overquoting is evil! 👎
Re: Copying files from list
I guess I haven't seen it.white wrote: 2026-05-16, 11:37 UTC I don't think so, but I did mention this syntax on the forum before.
Don't know for sure, i can count them on Monday, but I believe it is below the limit.
Re: Copying files from list
Let's say you have:
The user button:
The script (copy_files_from_list.ps1):
Video illustration:
https://streamable.com/q1bz2d
Edit: code optimization
- a list file where the filenames are listed, e.g. 'd:\Downloads\copy_files_from_list.txt'
- an active (source) directory in TC (%P) that can define:
- a. (version 1) a source disk where the files in question can reside
- b. (version 2) a source directory within which the files in question can reside
- a passive (target) directory in TC (%T) as the destination
- Read the list file
- Search for the files with the listed filenames within possible sources (see version 1, version 2)
- Copy the files into the destination, preserving the directory structures, respecting the specifics of the sources (see version 1, version 2)
Code: Select all
[em_read_filenames_listed_in_a_text_file_then_find_those_files_who_knows_where_and_then_copy_them_into_the_destination_directory_preserving_original_directory_structure]
cmd=pwsh -c "d:\Downloads\copy_files_from_list.ps1"
param=%P '%T'Code: Select all
TOTALCMD#BAR#DATA
em_read_filenames_listed_in_a_text_file_then_find_those_files_who_knows_where_and_then_copy_them_into_the_destination_directory_preserving_original_directory_structure
WCMICON2.DLL
user command: read filenames from a text list file, find those files somewhere, and then copy them into a dynamic destination preserving original directory structure
-1
Code: Select all
$time = [diagnostics.stopwatch]::StartNew()
if(-not $args){
'no input parameters have been passed; nothing to do here, exiting...'
sleep -second 3
exit
}
'input parameters:'|Write-Host -f Yellow
'[0] source path %P : {0}' -f $args[0];$sourcePath = $args[0] # %P current source path
'[1] target path %T : {0}' -f $args[1];$targetPath = $args[1] # %T current target path
''
$list = 'd:\Downloads\copy_files_from_list.txt'
if(-not [IO.File]::Exists($list)){
'no valid filenames list has been found; nothing to do here, exiting...'
sleep -second 3
exit
}
$filenames = [IO.File]::ReadLines((Get-Item -path $list))|foreach{$_}
if($filenames.count -eq 0){
'no filenames have been found in the provided list; nothing to do here, exiting...'
sleep -second 3
exit
}
'filenames list:'|Write-Host -f Yellow
for ($i=0;$i -lt $filenames.count;$i++){
'[{0}] : {1}' -f $i,$filenames[$i]|Write-Host -f Green
}
''
'find and copy files from a filenames list into a destination preserving the directory structure...'|Write-Host -f Yellow
''
'phase 1 (version 1) : files are somewhere within the disk where the $sourcePath (%P) resides:'|Write-Host -f Yellow
$path = (Get-Item $sourcePath).PSDrive.Root
$files = Get-ChildItem -path $path -file -force -recurse -EA:silent|Where{$_.Name -in $filenames -and $_.FullName -notlike '*\$RECYCLE.BIN\*'}
foreach ($file in $files){
# [IO.Path]::GetRelativePath($path,$file)
$suffix = [IO.Path]::GetRelativePath($path,$file)
$destination = [IO.FileInfo][IO.Path]::combine($targetPath,$suffix)
$destinationPath = $destination.Directory
if(-not [IO.Directory]::Exists($destinationPath)){
New-Item $destinationPath -type directory -force|Out-Null
}
'{0} >> {1}' -f $file.FullName,$destination.FullName
Copy-Item $file $destination -force
}
'{0} files have been copied' -f $files.count
$firstPhase = $time.Elapsed
'{0:mm\:ss\.fff} : the first phase timing' -f $firstPhase
''
'phase 2 (version 2) : files are somewhere within the $sourcePath (%P):'|Write-Host -f Yellow
$path = $sourcePath
$files = Get-ChildItem -path $path -file -force -recurse -EA:silent|Where{$_.Name -in $filenames}
foreach ($file in $files){
# [IO.Path]::GetRelativePath($path,$file)
$suffix = [IO.Path]::GetRelativePath($path,$file)
$destination = [IO.FileInfo][IO.Path]::combine($targetPath,$suffix)
$destinationPath = $destination.Directory
if(-not [IO.Directory]::Exists($destinationPath)){
New-Item $destinationPath -type directory -force|Out-Null
}
'{0} >> {1}' -f $file.FullName,$destination.FullName
Copy-Item $file $destination -force
}
'{0} files have been copied' -f $files.count
$secondPhase = $time.Elapsed
'{0:mm\:ss\.fff} : the second phase timing' -f ($secondPhase-$firstPhase)
''
# finalizing
$time.Stop()
'{0:mm\:ss\.fff} : the total timing by {1}' -f $time.Elapsed,$MyInvocation.MyCommand.Name
sleep -second 33
https://streamable.com/q1bz2d
Edit: code optimization
Last edited by beb on 2026-05-18, 22:26 UTC, edited 5 times in total.
#278521 User License
Total Commander [always the latest version, including beta] x86/x64 on Win10 x64/Windows 11/Android 17
Total Commander [always the latest version, including beta] x86/x64 on Win10 x64/Windows 11/Android 17
Re: Copying files from list
2beb
Thanks for your effort.
+1 for Vivaldi on taskbar.
Thanks for your effort.
+1 for Vivaldi on taskbar.
Re: Copying files from list
2solid
My pleasure.
But this is a simple example. We can easily make it a bit more complicated, for instance, building the list dynamically from the file under cursor, from selected files, from all or specific files from the current directory (flat or recursive), and so on.
My pleasure.
But this is a simple example. We can easily make it a bit more complicated, for instance, building the list dynamically from the file under cursor, from selected files, from all or specific files from the current directory (flat or recursive), and so on.
There ain't a lot of alternatives out there since Opera Presto said, "So long, and thanks for all the fish."
#278521 User License
Total Commander [always the latest version, including beta] x86/x64 on Win10 x64/Windows 11/Android 17
Total Commander [always the latest version, including beta] x86/x64 on Win10 x64/Windows 11/Android 17
Re: Copying files from list
I have now created the wiki page How-to: Copy files using filename list. So now this syntax is documented theresolid wrote: 2026-05-16, 10:48 UTCThanks a lot for this hint. It is exactly what I needed.white wrote: 2026-05-15, 21:48 UTC ... So transform your list to this format:And then use the LOADSELECTION command to load the selection.Code: Select all
*"file 1.txt" *"file 2.exe" *"file 3" ...
Is this syntax actually documented somewhere?
