How to make button to create new folder with name PDF

English support forum

Moderators: Hacker, petermad, Stefan2, white

jeee_michel
Junior Member
Junior Member
Posts: 13
Joined: 2022-04-19, 15:04 UTC

How to make button to create new folder with name PDF

Post by *jeee_michel »

Is it possible to make this kind of button only for currently active tab?

1. To create button which will be creating new folder with name PDF
2. Copy all files with extension .pdf in the created folder
3. Run all copied files with software for example ("D:Acrobat.exe")
User avatar
beb
Power Member
Power Member
Posts: 580
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: How to make button to create new folder with name PDF

Post by *beb »

Button:

Code: Select all

TOTALCMD#BAR#DATA
em_pdf

wciconex.dll
pdf


10034
usercmd.ini User command:

Code: Select all

[em_pdf]
cmd=Powershell sv -name from -value ".\from";sv -name to -value ".\pdf";if (-not ("$to"|Test-Path)) {md "$to"};gci $from -recurse -filter *.pdf | %{copy-item $_.Fullname $to -Force -ErrorAction SilentlyContinue};gci $to -recurse -filter *.pdf | %{Invoke-Item $_.Fullname}
Instead of the ".\from" path you have to type the actual source path where to look for your .pdf files, e.g., "d:\MyPdfFilesMayBeFoundSomewhereDownThere".
All the .pdf files from the source path would be copied into the "pdf" folder [that would be made] in the TC active panel and then opened in your default pdf app.
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10/15
jeee_michel
Junior Member
Junior Member
Posts: 13
Joined: 2022-04-19, 15:04 UTC

Re: How to make button to create new folder with name PDF

Post by *jeee_michel »

Thanks! works perfectly !
jeee_michel
Junior Member
Junior Member
Posts: 13
Joined: 2022-04-19, 15:04 UTC

Re: How to make button to create new folder with name PDF

Post by *jeee_michel »

Hello! I edited littlebit the command

instead of %{Invoke-Item $_.Fullname} at the end i changed to %{& C:\CMYK.exe $_.Fullname}

Technically its working at begining but later it stops working and i wonder where im making mistake..

[em_pdf]
cmd=Powershell sv -name to -value ".\pdf";if (-not ("$to"|Test-Path)) {md "$to"};gci $from -recurse -filter *.pdf | %{copy-item $_.Fullname $to -Force -ErrorAction SilentlyContinue};gci $to -recurse -filter *.pdf | %{& C:\CMYK.exe $_.Fullname}
User avatar
beb
Power Member
Power Member
Posts: 580
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: How to make button to create new folder with name PDF

Post by *beb »

2jeee_michel
Apparently, your app cannot process incoming data in a timely manner. In other words, gci (Get-ChildItem) pipes files a bit faster than CMYK.exe opens them.
Therefore, "Start-Process ... -Wait" method should be used.

Code: Select all

[em_pdf]
cmd=Powershell sv -name from -value ".\from";sv -name to -value ".\pdf";if (-not ("$to"|Test-Path)) {md "$to"};gci $from -recurse -filter *.pdf | %{copy-item $_.Fullname $to -Force -ErrorAction SilentlyContinue};gci $to | foreach-object -process {Start-Process -FilePath "C:\CMYK.exe" -ArgumentList $_ -WorkingDir "$to" -Wait}
The above command would work, but ONLY if your pdfs names don't have spaces. AND -- files would be opened one by one: i.e., CMYK.exe opens the first file, you do whatever you do with it and close the app, then the app starts with the second file, and so on.
If your pdfs names do contain spaces this won't work either, because TC doesn't accept the double quotes in -ArgumentList $_, and I could find no workaround for that whatever PowerShell syntax I use to set them there.
Again, if your pdfs names do contain spaces there should be the other way to do the task.
Last edited by beb on 2023-04-12, 05:41 UTC, edited 1 time in total.
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10/15
User avatar
beb
Power Member
Power Member
Posts: 580
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: How to make button to create new folder with name PDF

Post by *beb »

This approach should be workable:
ps_test_pdf.ps1:

Code: Select all

$bin   = "c:\CMYK\bin\CMYK.exe"
$from  = "c:\CMYK\from"
$to    = "c:\CMYK\pdf"
if (-not ("$to"|Test-Path)) {md "$to" > $null}
Get-ChildItem $from -recurse -filter *.pdf | %{copy-item $_.Fullname $to -Force -ErrorAction SilentlyContinue}
$found = (Get-ChildItem $to -recurse -include *.pdf)
foreach ($pdf in $found) {
"pdf   : $pdf"
$param = """$pdf"""
Start-Process $bin -ArgumentList $param -WorkingDir "$to" -Wait
}
usercmd.ini:

Code: Select all

[em_test_pdf]
cmd=Powershell
param=-ExecutionPolicy Bypass c:\CMYK\ps\ps_test_pdf.ps1
button:

Code: Select all

TOTALCMD#BAR#DATA
em_test_pdf

wciconex.dll
pdf

0
10035
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10/15
User avatar
beb
Power Member
Power Member
Posts: 580
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: How to make button to create new folder with name PDF

Post by *beb »

And here comes "one-stringer" again. No separate .ps1 needed.

usercmd.ini:

Code: Select all

[em_test_pdf]
cmd=Powershell -ExecutionPolicy Bypass -NoLogo
param=-command set from -value "c:\CMYK\from"; set pdf -value "c:\CMYK\pdf"; if (-not ($pdf|Test-Path)) {md $pdf}; gci $from -recurse -filter *.pdf | foreach-object -process {copy-item $_.fullname $pdf -Force -ErrorAction SilentlyContinue}; gci $pdf -filter *.pdf | foreach-object -process {Start-Process "c:\CMYK\bin\CMYK.exe" -ArgumentList $('"""'+$_.fullname+'"""') -WorkingDir $pdf -Wait}
button:

Code: Select all

TOTALCMD#BAR#DATA
em_test_pdf

wciconex.dll
pdf

0
10007
NB -ArgumentList $('"""'+$_.fullname+'"""') construction has managed to wrap $_.fullname into "double quotes" while feeding -ArgumentList as required, so em_test_pdf can now process pdfs with blank spaces in names.

NBNB syntax comparison:
This one runs under pure PowerShell but won't run under TC (em_*@usercmd.ini):

Code: Select all

Start-Process "c:\CMYK\bin\CMYK.exe" -ArgumentList $('"'+$_.fullname+'"') -Wait}
This one runs under TC (em_*@usercmd.ini) but won't run under pure PowerShell:

Code: Select all

Start-Process "c:\CMYK\bin\CMYK.exe" -ArgumentList $('"""'+$_.fullname+'"""') -Wait}
NBNBNB if needed, powershell processes TC variables, so a user can make related commands (as in question) dynamic and universal.
To illustrate that here below is a simple example that utilizes %T (target panel directory), %P (source panel directory), $env:commander_path (TC directory) all at once (it lists %T and %P contents, finds and outputs all the plugins related .ini (such as default contplug.ini, fsplugin.ini, lsplugin.ini, pkplugin.ini))

Code: Select all

[em_test_powershell]
cmd=Powershell -ExecutionPolicy Bypass
param=dir %T;dir %P; dir $env:commander_path -filter *.ini | Where-Object {$_.Name -match 'plug'} | foreach-Object -process {Write-Host $_.fullname};pause
'dir' here is just another alias of 'Get-ChildItem' (aka 'list', 'ls', 'gci').
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10/15
jeee_michel
Junior Member
Junior Member
Posts: 13
Joined: 2022-04-19, 15:04 UTC

Re: How to make button to create new folder with name PDF

Post by *jeee_michel »

Thanks a lot for the explanation!
User avatar
beb
Power Member
Power Member
Posts: 580
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: How to make button to create new folder with name PDF

Post by *beb »

beb wrote: 2023-04-11, 21:56 UTC 2jeee_michel
Apparently, your app cannot process incoming data in a timely manner. In other words, gci (Get-ChildItem) pipes files a bit faster than CMYK.exe opens them.
Therefore, "Start-Process ... -Wait" method should be used...
2jeee_michel

My bad. There's a workaround for that case that I use from time to time but it somehow completely slipped off my mind at a time.
You can insert a time pause before or after the command that makes your app to processes your files.
Of course, this pause has to be long enough to overlap the gaps between the command execution iterations.
E.g., "Start-Sleep -Seconds 1; foo-command $app $file" or "foo-command $app $file; Start-Sleep -Seconds 1".
As could be seen, the Start-Sleep syntax is pretty transparent, and a user can type there as many seconds as needed for a specific task.

So, if {& C:\CMYK.exe $_.Fullname} had been working for you at the beginning maybe it is worth trying something like that {& C:\CMYK.exe $_.Fullname; Start-Sleep -Seconds 2} and see if it works for the whole task (and increase/decrease the pause as needed).
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10/15
jeee_michel
Junior Member
Junior Member
Posts: 13
Joined: 2022-04-19, 15:04 UTC

Re: How to make button to create new folder with name PDF

Post by *jeee_michel »

I think this is good solution with {& C:\CMYK.exe $_.Fullname; Start-Sleep -Seconds 2} !
Everything work perfectly good now! Thanks a lot!
jeee_michel
Junior Member
Junior Member
Posts: 13
Joined: 2022-04-19, 15:04 UTC

Re: How to make button to create new folder with name PDF

Post by *jeee_michel »

[em_pdf]
cmd=Powershell sv -name to -value ".\pdf";if (-not ("$to"|Test-Path)) {md "$to"};gci $from -recurse -filter *.pdf | %{copy-item $_.Fullname $to -Force -ErrorAction SilentlyContinue};gci $to -recurse -filter *.pdf | %{& C:\CMYK.exe $_.Fullname; Start-Sleep -Seconds 2}

is it possible to use powershell command only for selected files? lets say i have 10 pdfs but i select only 2-3 with total commander and it works only for them , this works for another applications if i set to parameters %P%S
User avatar
beb
Power Member
Power Member
Posts: 580
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: How to make button to create new folder with name PDF

Post by *beb »

jeee_michel wrote: 2023-04-13, 14:35 UTC [em_pdf]
cmd=Powershell sv -name to -value ".\pdf";if (-not ("$to"|Test-Path)) {md "$to"};gci $from -recurse -filter *.pdf | %{copy-item $_.Fullname $to -Force -ErrorAction SilentlyContinue};gci $to -recurse -filter *.pdf | %{& C:\CMYK.exe $_.Fullname; Start-Sleep -Seconds 2}
1. To begin with, your command does not define the "$from" variable but still explicitly tries to use it (see "gci $from -recurse").
If you don't use "$from" it would be better to not put it there.
As I may assume, you run the command being within a directory where your source pdfs are located.
Luckily, if the "$from" is empty, that part just takes the TC current directory as the root and you may seem it works as intended.
Still, it would be better to get rid of it.
So, let us put the initial command as follows:

Code: Select all

[em_pdf]
cmd=Powershell sv -name to -value ".\pdf";if (-not ("$to"|Test-Path)) {md "$to"};gci -recurse -filter *.pdf | %{copy-item $_.Fullname $to -Force -ErrorAction SilentlyContinue};gci $to -recurse -filter *.pdf | %{& C:\CMYK.exe $_.Fullname; Start-Sleep -Seconds 2}
And even better as follows (putting it in two lines, replacing abstract "$to" by a bit more targeted "$pdf", and implementing a separate variable "$bin" for binary, all for the sake of better reading and convenience*):

Code: Select all

[em_pdf]
cmd=Powershell -ExecutionPolicy Bypass; set bin -value "C:\CMYK.exe"; set -name pdf -value ".\pdf"; if (-not ($pdf|Test-Path)) {md $pdf};
param=gci -recurse -filter *.pdf | %{copy-item $_.Fullname $to -Force -ErrorAction SilentlyContinue};gci $pdf -recurse -filter *.pdf | %{& $bin $_.Fullname; Start-Sleep -Seconds 2}
[*] I don't have an idea what is "CMYK.exe" so I'm putting my own apps there and "$bin" at least would allow me to avoid excessive errors upon copying/pasting the code since the sensitive code remains only in the second line.

2. Returning to your actual question, to begin with, let us see how your app would handle the command as follows:

Code: Select all

[em_pdf_selected]
cmd=Powershell -ExecutionPolicy Bypass; set bin -value "C:\CMYK.exe";
param=write-host "%P%S";& $bin "%P%S";pause
As you would be able to see (via "write-host "%P%S"" output), "%P%S" would return a string that consists of the selected files' full names separated by the blank space(s).
My test pdf applications[*] just open all the selected pdfs upon execution of the above command.
[*] By the way, maybe you could share that "CMYK.exe" for better testing?
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10/15
User avatar
beb
Power Member
Power Member
Posts: 580
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: How to make button to create new folder with name PDF

Post by *beb »

Again, if pdfs names contain spaces %P%S output becomes practically useless since it ain't no easy and user-friendly way to split such a spacious string into meaningful parts (to extract separate file names in the end).
Therefore, it's better (much simpler) to use %L instead of %P%S here.
The below command would process any selected files, including ones with spaces:

Code: Select all

[em_pdf_selected]
cmd=Powershell -ExecutionPolicy Bypass; set bin -value "C:\CMYK.exe";
param=write-host "%L";Get-Content "%L"|ForEach-Object -process {write-host $('"""'+$_+'"""');& $bin $('"""'+$_+'"""')};pause
NB "write-host..." and "pause" parts don't do actual work there, just allow you to see what data you are dealing with and understand where to go to. As soon as the command passes the workability exam we would wipe them out.
It's just a thing of how TC usercmd.ini syntax represents itself as ridiculously outdated here.
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10/15
jeee_michel
Junior Member
Junior Member
Posts: 13
Joined: 2022-04-19, 15:04 UTC

Re: How to make button to create new folder with name PDF

Post by *jeee_michel »

The exe which i have is from Acrobat Preflight i created droplet which is called CMYK.exe its making all colors to CMYK using adobe color engine.

here is the exe which should work for anyone who has acrobat DC https://we.tl/t-XZZSOsfO7g

[em_pdf_selected]
cmd=Powershell -ExecutionPolicy Bypass; set bin -value "C:\CMYK.exe";
param=write-host "%P%S";& $bin "%P%S";pause

this button works pretty good! the only thing which i notice if file is called "for print" its getting confused as for.pdf and print.pdf as 2 files i think
and i removed pause from the end of param= because powershell windows was giving me message "press enter"

[em_pdf]
cmd=Powershell -ExecutionPolicy Bypass; set bin -value "C:\CMYK.exe"; set -name pdf -value ".\pdf"; if (-not ($pdf|Test-Path)) {md $pdf};
param=gci -recurse -filter *.pdf | %{copy-item $_.Fullname $to -Force -ErrorAction SilentlyContinue};gci $pdf -recurse -filter *.pdf | %{& $bin $_.Fullname; Start-Sleep -Seconds 2}

i like this variant but here something is not working for some reason :<
jeee_michel
Junior Member
Junior Member
Posts: 13
Joined: 2022-04-19, 15:04 UTC

Re: How to make button to create new folder with name PDF

Post by *jeee_michel »

[em_pdf_selected]
cmd=Powershell -ExecutionPolicy Bypass; set bin -value "C:\CMYK.exe";
param=write-host "%L";Get-Content "%L"|ForEach-Object -process {write-host $('"""'+$_+'"""');& $bin $('"""'+$_+'"""')};pause

yeah now it works with spaces also! amazing! i guess its safe to remove pause from the end of param= ?
Post Reply