How to create a TC button cooperating with batch file

English support forum

Moderators: sheep, Hacker, Stefan2, white

Post Reply
User avatar
dmocha
Junior Member
Junior Member
Posts: 25
Joined: 2013-05-05, 19:09 UTC
Location: Poland

How to create a TC button cooperating with batch file

Post by *dmocha » 2019-02-21, 22:09 UTC

Hi,

I would like to have a button to pack the selected files (or directories).
The target 7z file should have the current time and date in its name.
I have a small batch file, but I don't know how to use it in a TC button in such a way that it works on selections.

Probably I have to use the parameter /%S
How?

Code: Select all

@echo off
set y=%date:~6,4%
set m=%date:~3,2%
set d=%date:~0,2%
set hr=%time:~0,2%
if "%hr:~0,1%" == " "  set hr=0%h:~1,1%
set min=%time:~3,2%
set sec=%time:~6,2%
set stamp=%y%.%m%.%d%_%hr%.%min%.%sec%
echo %stamp%
c:\tool\7z_cmd\7za.exe a file_%stamp%.7z source_file
Is it at all possible?
regards
dmocha

User avatar
Dalai
Power Member
Power Member
Posts: 6456
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Re: How to create a TC button cooperating with batch file

Post by *Dalai » 2019-02-21, 22:52 UTC

Take a look at the 7zip help file, section Command line version > Syntax. Search for "list file" and you'll see this example:

Code: Select all

7z a -tzip archive.zip @listfile.txt
You should be able to use that in your script like so:

Code: Select all

c:\tool\7z_cmd\7za.exe a "file_%stamp%.7z" "@%~1"
with a button in TC that uses a list file as parameter to your batch script:

Code: Select all

script.cmd "%UL"
Not sure if 7z[a].exe expects list files with a BOM or not, but I'm sure you can figure that out :), or change the list file charset as explained in 7z help.

Regards
Dalai
#101164 Personal licence
Athlon X4 880K, 16 GiB RAM, Gigabyte F2A88X-D3HP, Win7 x64

Plugins: Services2, Startups

User avatar
dmocha
Junior Member
Junior Member
Posts: 25
Joined: 2013-05-05, 19:09 UTC
Location: Poland

Re: How to create a TC button cooperating with batch file

Post by *dmocha » 2019-02-23, 21:23 UTC

Thanks, it works
regards
dmocha

Post Reply