Is there a way to create a custom copy action?

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
DelphiDev
Junior Member
Junior Member
Posts: 94
Joined: 2019-03-22, 12:03 UTC

Is there a way to create a custom copy action?

Post by *DelphiDev »

Hey there,

many times a day I copy a build output from our build share to my local %programfiles% and overwrite all existing files.
So I need to
  • Ctrl + A (Select all files from folder in left panel)
  • F5 (copy selected files to folder in right panel)
  • Return (Confirm copy)
  • Alt + A (Overwrite all files)
  • Alt + L (All as Administrator)
  • Y (confirm UAC)
Is there a way to encapsulate these steps into a single action? (UAC will still be necessary, I know and I can live with that)

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

Re: Is there a way to create a custom copy action?

Post by *vdijken »

Synchronize directories?
DelphiDev
Junior Member
Junior Member
Posts: 94
Joined: 2019-03-22, 12:03 UTC

Re: Is there a way to create a custom copy action?

Post by *DelphiDev »

I figured that a batch file would be the easiest way to accomplish this.
So I created a batch file test.bat

Code: Select all

xcopy %1 %2 /O/X/E/H/K
I then created a new button in TC.
Command: *D:\test.bat (* for elevation)
Parameters: "%P" "%T" (%P source dir, %T target dir)

Clicking the button however does not execute the batch file. When I omit the quotation marks the batch file executes as expected, with the quotation marks the batch file does not seem to be executed. I even added "pause" to the end of the batch but it doesn't pause hence was not executed at all. (cmd window opens and closes directly)

When I omit the * to elevate the batch, the quoted parameters work. (tested with echo %1) But since I need elevation to be able to write to %programfiles% I need the *.

Is there a bug with starting a batch elevated and quoted parameters?
User avatar
norfie²
Power Member
Power Member
Posts: 986
Joined: 2006-02-10, 07:27 UTC

Re: Is there a way to create a custom copy action?

Post by *norfie² »

This doesn't need a batch file. Xcopy can be used directly.
"War is evil, in so far as it makes more bad people than it takes away."
Immanuel Kant in "Perpetual Peace"
User avatar
Stefan2
Power Member
Power Member
Posts: 4132
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: Is there a way to create a custom copy action?

Post by *Stefan2 »

DelphiDev wrote: 2019-07-05, 09:29 UTC Is there a bug with starting a batch elevated and quoted parameters?
User and elevated admins are different user accounts. So,... what is your target dir?
Try to launch a cmd window and there try to browse to source and target folders,... are they available for the elevated user?

You can also use ""RunAs" in your batch:
runas /user:you xcopy %1 %2 /O/X/E/H/K



Or try like norfie² mentioned:
Command: *xcopy
Parameters: "%P" "%T"




 
User avatar
norfie²
Power Member
Power Member
Posts: 986
Joined: 2006-02-10, 07:27 UTC

Re: Is there a way to create a custom copy action?

Post by *norfie² »

Mark the text below, copy to clipboard and paste as button into the button bar.

Code: Select all

TOTALCMD#BAR#DATA
*%SystemRoot%\System32\xcopy.exe
"%P". "%T". /EHKOX
totalcmd.exe,2
Xcopy with Admin


-1
"War is evil, in so far as it makes more bad people than it takes away."
Immanuel Kant in "Perpetual Peace"
DelphiDev
Junior Member
Junior Member
Posts: 94
Joined: 2019-03-22, 12:03 UTC

Re: Is there a way to create a custom copy action?

Post by *DelphiDev »

Thanks @ all.
I'm still struggling to find the culprit.
Can I somehow pipe the output to a text file?
adding " > d:\output.txt" to the parameters doesn't work as expected. (Yes, D: exists and I can write there)
User avatar
norfie²
Power Member
Power Member
Posts: 986
Joined: 2006-02-10, 07:27 UTC

Re: Is there a way to create a custom copy action?

Post by *norfie² »

2DelphiDev
Did you test my button? (I tested it and it works for me like a charm :D)
There is a problem with admin account and path variable. You need to specify the whole path to xcopy.exe.
Another problem are the backslash signs in the end of the source path and target path. Xcopy don't like that therefore I putted a dot at the end of source path and target path. If you don't like that you could put a file mask with asterisks *.* at each end of paths.
Last edited by norfie² on 2019-07-05, 12:27 UTC, edited 2 times in total.
"War is evil, in so far as it makes more bad people than it takes away."
Immanuel Kant in "Perpetual Peace"
User avatar
Stefan2
Power Member
Power Member
Posts: 4132
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: Is there a way to create a custom copy action?

Post by *Stefan2 »

DelphiDev wrote: 2019-07-05, 11:51 UTC
Can I somehow pipe the output to a text file?
Which "output"? What you're talking about now exactly? (my crystal bowl is broken)

What do you want to output? StdOut? StdErr? Try ....1&2> d:\output.txt"...

You can also add a leading '?' in the parameter box to see what TC will execute.
Parameters: ?"%P" "%T"
Maybe that will give you a glue?



 
DelphiDev
Junior Member
Junior Member
Posts: 94
Joined: 2019-03-22, 12:03 UTC

Re: Is there a way to create a custom copy action?

Post by *DelphiDev »

norfie² wrote: 2019-07-05, 12:16 UTC 2DelphiDev
Did you test my button? (I tested it and it works for me like a charm :D)
There is a problem with admin account and path variable. You need to specify the whole path to xcopy.exe.
Another problem are the backslash signs in the end of the source path and target path. Xcopy don't like that therefore I putted a dot at the end. If you don't like that you could put a file mask mit asteriks *.*
Yes I did and unfortunately it also closes directly. Must have something to do with either my source or target path. The weird thing is that this only happens when I quote %T (which is "c:\Program Files (x86)\MySuperDuperApp\" hence the need to use quotation marks). It works with a target path that does not have a space in its name and thus doesn't need quotes.

@Stefan2 StdOut, yes.

I'd like to pipe StdOut of xcopy to a text file so that I can better analyze the problem.
User avatar
norfie²
Power Member
Power Member
Posts: 986
Joined: 2006-02-10, 07:27 UTC

Re: Is there a way to create a custom copy action?

Post by *norfie² »

My button works for me with
C:\Program Files (x86)\MySuperDuperApp\
as target path.
Which windows version do you use?

For debugging issue you could use the following button:

Code: Select all

TOTALCMD#BAR#DATA
*%COMSPEC% /c(%SystemRoot%\System32\xcopy.exe
"%P". "%T". /EHKOX || PAUSE)
totalcmd.exe,2
Xcopy with Admin


-1
"War is evil, in so far as it makes more bad people than it takes away."
Immanuel Kant in "Perpetual Peace"
User avatar
petermad
Power Member
Power Member
Posts: 14739
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Is there a way to create a custom copy action?

Post by *petermad »

2DelphiDev
This button works fine for me:

Code: Select all

TOTALCMD#BAR#DATA
*%SystemRoot%\System32\xcopy.exe
"%P". "%T". /HRKYEOX
%COMMANDER_EXE%,2
Xcopy with Admin

1
-1
To make the button:
1. Mark the green text above (click SELECT ALL).
2. Copy it to the ClipBoard (press Ctri+C).
3. Right click on TC's buttonbar and choose "Paste".
Please use this method to make the button, to rule out typing errors.

If you don't want subdirs copied - remove the E from /HRKYEOX
If you don't want to copy file ownership - remove the O from/HRKYEOX
If you don't want to copy file audit settings - remove the X from/HRKYEOX

Compared to the others here, I have added R to overwrite read-only files, and Y to not ask for permission to owerwrite. I have also used %COMMANDER_EXE%,2 in stead of totalcmd.exe,2 - this way you wil get an icon on your button in both 32- and 65bit TC
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
Post Reply