Copy files to specified folders depending on their filename?

English support forum

Moderators: white, Hacker, petermad, Stefan2

hiccup
Junior Member
Junior Member
Posts: 63
Joined: 2018-05-13, 08:04 UTC

Copy files to specified folders depending on their filename?

Post by *hiccup »

Hi there.

I am a Total Newbee with Total Commander, and only just started getting my feet wet.
One of the things I would like to accomplish is this:

I want to create a shortcut button that copies files to specific folders depending on their filenames.
E.g. when a file name contains the word 'cat', it gets copied to a folder named 'Animals'.
Or when a filename contains the word 'soup', it gets copied to a folder named 'Food'.

Could somebody confirm if this can be done, and possibly help me in the right direction for how to achieve this?

Tia!
User avatar
vdijken
Member
Member
Posts: 181
Joined: 2016-07-30, 14:07 UTC
Location: The Netherlands

Post by *vdijken »

Do the following steps.
1) Select origin and target directories left and right
2) Search the files with CTRL-S.
3) Select those files with CTRL-A
4) Copy the files with F5 (or move with F6).

When you want to copy files from multiple directories use ALT-F7 in step 1) to find files, but there is always a change that you find more files then you want in underlying directories!
hiccup
Junior Member
Junior Member
Posts: 63
Joined: 2018-05-13, 08:04 UTC

Post by *hiccup »

Thank you for replying vdijken.

But I fail to see how your answer is a solution to what I am asking.
User avatar
Ovg
Power Member
Power Member
Posts: 756
Joined: 2014-01-06, 16:26 UTC

Post by *Ovg »

2hiccup
I think that this can be done only via script or you can define and save search parameters for finding files you need and copy them to desired folder after they are found. Please see Help section 3.c->Commands->Search->dialog box Find files
It's impossible to lead us astray for we don't care even to choose the way.
#259941, TC 11.01 x64, Windows 7 SP1 x64
User avatar
petermad
Power Member
Power Member
Posts: 14739
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Post by *petermad »

It is just those two examples you want a solution for?

If not, where should 'cow' go? - to "Animals" or 'Food'?
And what about 'catfish'?

I am afraid the this will require a lot of AI to cower just some of the possibilities.
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50b4 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
Ovg
Power Member
Power Member
Posts: 756
Joined: 2014-01-06, 16:26 UTC

Post by *Ovg »

2petermad
i think that:
Cow - Animals
Beef - Food :mrgreen:
It's impossible to lead us astray for we don't care even to choose the way.
#259941, TC 11.01 x64, Windows 7 SP1 x64
hiccup
Junior Member
Junior Member
Posts: 63
Joined: 2018-05-13, 08:04 UTC

Post by *hiccup »

Thanks Ovg and petermad,

'animals' and 'food' were only used as an example to make it clear what I would like to achieve.
In my actual scenario, there would only be about 20 keywords that would define to what folders the files should be copied.
They have nothing to do with food or animals, so I wouldn't have to worry about a cow being an animal or food ;-)

I was imagining (hoping) that there might be a way to select a file, and when I press a customized 'copy' button, it will check if one of those 20 'keywords' is present in the filename (perhaps by means of regex), and then copy the file to a folder that is linked to that 'keyword'.

What might make it even clearer what I am trying to achieve, and I could imagine perhaps some TC users already have working:

Suppose you want to copy files to specific folders depending on their extensions.
So if you have a *.jpg in a folder, you could copy it to an 'Images' folder with one click.
And a file such as *.pdf would automagically be copied to 'PDF's'.

I hope this makes sense?
User avatar
Stefan2
Power Member
Power Member
Posts: 4133
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Post by *Stefan2 »

2hiccup

You can do that by utilizing a script (VBS, PowerShell, AutoHotkey,...)


TC will support you by providing a list with names of the selected files.
(Right click on of the button, > Change..., > press F1 and read the help about %L and %F)




In your script you can do smtg like:

- For each file X in TCs "%L" temp list:
--- If In String 'cat' THEN copy (or move) X to 'Animals'
--- If In String 'soup' THEN copy X to 'Food'
--- If Extension = 'jpg' THEN copy X to 'Images'
--- If Extension = 'pdf' THEN copy X to 'PDFs'
--- next file


You can also note if you want "Whole Word only" and "Case sensitive" match.


Searching the forum will find many such scripts.
f.ex.: viewtopic.php?p=335876#335876





Next you can create an button like:
Command: "D:\rive\path to my\Script.ext
Parameter: "%L"


You can even create a user defined command, which is more flexible as you can use it as button command and also assign an shortcut to.


More about that you can read there > viewtopic.php?p=287965#287965

And here (German only) > viewtopic.php?t=49107



If you need help by creating such a script, just ask and there are many who will aid you.




 
hiccup
Junior Member
Junior Member
Posts: 63
Joined: 2018-05-13, 08:04 UTC

Post by *hiccup »

Thank you Stefan2!

It looks like that might be the solution for what I am looking for.
It's a bit above my current understanding and capabilities, but I'll try to figure it out.
This forum seems very helpful and friendly, so if I don't succeed myself, I'll be back for some more assistance.
User avatar
petermad
Power Member
Power Member
Posts: 14739
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Post by *petermad »

2hiccup
I knew that "cat", "animal" etc. was just examples, I just tried to illustrate that it can be difficukt to cover all situations in a script.

Could you give a couple of examples of how the full filename could look?
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50b4 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
Ovg
Power Member
Power Member
Posts: 756
Joined: 2014-01-06, 16:26 UTC

Post by *Ovg »

2hiccup
I wrote AHK script for you task.
https://yadi.sk/d/6OuZuavj3VqPmj

You have to install Autohotkey from www.autohotkey.com
or I can compile this script to exe file, and then you no need in Autohotkey.

Ini file should resides in the same folder with script.
Ini should be saved in UTF-16 with BOM in case of editing.

[0]
Overwrite=1 - existing files in target directory will be overwritten
0 - existing files in target directory will be preserved

[1]
Keys=list of keywords delimited with "/"
Target=Target directory for files containing keywords
and so on.

If the target directory doesn't exist, it will be created.

button example:

Code: Select all

 
TOTALCMD#BAR#DATA
n:\FilesCopy.ahk
%UL
C:\Program Files\AHK\AutoHotkey.exe
FilesCopy
n:\

-1
Change paths to your actual paths and icon for you taste

You have to select files and press button
Last edited by Ovg on 2018-05-14, 04:55 UTC, edited 3 times in total.
It's impossible to lead us astray for we don't care even to choose the way.
#259941, TC 11.01 x64, Windows 7 SP1 x64
hiccup
Junior Member
Junior Member
Posts: 63
Joined: 2018-05-13, 08:04 UTC

Post by *hiccup »

@Ovg

Wow!
It's gonna take at least a couple of days before I can try this out, but it looks like an interesting, and hopefully fun challenge that should be doable for me.
I'll report back after I have found the time. (and courage ;-)


@petermad
Looking at the previous post from Ovg, there's probably no need to explain it further, but to respectfully answer you:

I'll stick with the animal-food example, but forget about thinking what 'food' is or what 'animals' are.
It's all just about recognizing if a word from a preset list (containing approx. 20 items) exists in the selected filename.
If it does, that word should determine to what folder the file will be copied/moved to.

e.g.:

cat.siamese.001.jpg
persian.cat_family-tree.txt
potato.soup-recipe.doc
FrenchOnionSoup.png

The first two should go to a folder named 'Animals'. ('cat' is matched)
The last two should go to a folder named 'Food'. ('soup' is matched)
(both folders have already been created)

And also don't worry about "what if catsoup is in the title?"
That will probably never happen in my user case, since the words in my list are longer and quite unique.

On an additional note, I am not looking for a solution that searches a folder for all filenames that match one of those words.
I want it to work by selecting a file, and then activating the shortcut copy/move button for the selected file(s) only.
User avatar
Ovg
Power Member
Power Member
Posts: 756
Joined: 2014-01-06, 16:26 UTC

Post by *Ovg »

2hiccup

I have found and fixed a small bug. Please re-download file
from my post. Link is the same.
Last edited by Ovg on 2018-05-14, 04:56 UTC, edited 1 time in total.
It's impossible to lead us astray for we don't care even to choose the way.
#259941, TC 11.01 x64, Windows 7 SP1 x64
User avatar
Hacker
Moderator
Moderator
Posts: 13052
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Post by *Hacker »

hiccup,
For very simple filenames the Multi-Rename Tool (Ctrl-M) could work like this:

Code: Select all

Search for: beef|cat
Replace with: food\beef|animals\cat
Roman
Mal angenommen, du drückst Strg+F, wählst die FTP-Verbindung (mit gespeichertem Passwort), klickst aber nicht auf Verbinden, sondern fällst tot um.
hiccup
Junior Member
Junior Member
Posts: 63
Joined: 2018-05-13, 08:04 UTC

Post by *hiccup »

Ovg wrote:2hiccup

button example:

Code: Select all

 
TOTALCMD#BAR#DATA
n:\FilesCopy.ahk
%UL
C:\Program Files\AHK\AutoHotkey.exe
FilesCopy
n:\

-1
I don't understand where I should enter the above code exactly.
I am guessing I don't need to enter line 1 anywhere, and that lines 2,3 and 4 should be entered like this:

(edit: damn, link to screenshot was here, but I am not allowed to post an image??)

But what do I do with the remaining code lines?
Post Reply