move files like a drop target

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
terrmos
Junior Member
Junior Member
Posts: 3
Joined: 2024-09-11, 11:53 UTC

move files like a drop target

Post by *terrmos »

Hi,

I want to select certain files and drop them to a button in Total Commander's button bar, which in return moves them to a target location without confirmation.

What I have tried so far is, I made a move_files.bat file, I dragged the .bat file to TC's button bar, but the problem is it only moves the first file no matter the .bat code. I got help from Chat GPT but it still doesn't move more files then one. I tried Windows Power Shell, and I got the same result: just one file.

Is there any other way i can accomplish this? Maybe some internal command that I am not aware of?
I tried the cm_MoveFiles from TC but I couldn't make it work - Chat GPT was a pain guiding me to make that possible.


here is my .bat code generated by Chat GPT:




@echo off
setlocal

:: Check if any files were passed as arguments
if "%~1"=="" (
echo No files selected.
exit /b
)

:: Set destination directory
set "destination=C:\0"

:: Loop through each file passed as an argument and move it
:loop
if "%~1"=="" goto endloop
echo Moving "%~1" to "%destination%"
move "%~1" "%destination%"
shift
goto loop

:endloop
endlocal



I am running on Windows 10 if that's important.

Thank you for any suggestion
User avatar
Dalai
Power Member
Power Member
Posts: 9578
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Re: move files like a drop target

Post by *Dalai »

When dropping files onto a button in TC's button bar, TC replaces the parameters of that button with the first file that is dropped there. Try with this very simple script for example:

Code: Select all

@echo off
echo %*
pause
No matter how many files you select and drop onto a button that calls this script, you'll always see only the first one. That's just the way it is.

The only way around that is as follows:
  1. Create a button with %L in its parameters field
  2. Change your script to process the list file passed by TC (%L), e.g. with a for /F loop.
  3. Select the files and click the button (instead of dropping them onto it)
You could use %S instead of %L but you'll run into the command line length limit very very quickly, so I suggest to avoid doing that.
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
terrmos
Junior Member
Junior Member
Posts: 3
Joined: 2024-09-11, 11:53 UTC

Re: move files like a drop target

Post by *terrmos »

Thank you very much for your response, Dalai, it works very well !

I finally made it with to work with your help, I was stuck for few days on this and it was really frustrating.

Once again, a big thank you and have a nice day :)

*************

For anyone who might use this information, here is what I did to make it work:

My .bat file is located here C:\1 and my target folder is this c:\0 [ you need to change this with your location/target, obviously , and in the code you need to change the "targetDir=" with your target]

1. I made a move_file.bat with next code in it:

@echo off
set targetDir="C:\0\"

for /F "usebackq delims=" %%f in ("%~1") do (
move "%%f" %targetDir%
)


2. I drag the move_file.bat in the TC's button bar / right click on it / change / in the Parameters I have: %L
3. optional - I can pick an icon file for this button. / click ok

Back to TC main window / I select the files I want to move / click on the new button to move them
User avatar
white
Power Member
Power Member
Posts: 4992
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Re: move files like a drop target

Post by *white »

terrmos wrote: 2024-09-11, 13:04 UTC Back to TC main window / I select the files I want to move / click on the new button to move them
You could also utilize the cm_RenMov command with parameters. Search the help for "cm_RenMov" for more information.
For example, in its most basic form you could use parameter:

Code: Select all

/GT="C:\0\"
terrmos
Junior Member
Junior Member
Posts: 3
Joined: 2024-09-11, 11:53 UTC

Re: move files like a drop target

Post by *terrmos »

@ white - Thank you for your reply, this seems to work also. Up until this day none of my efforts were successful, and now I have more then one option :).

Thank you again for taking time to respond.
Post Reply