2
Galizza
Interesting question.
I've been using the following approach, and it works perfectly for me (however, without archives and clipboard yet):
User command (usercmd.ini):
Code: Select all
[em_test_tc_params_files_folders]
cmd=pwsh -c "%commander_path%\Plugins\app\PowerShell\echoParamFiles.ps1"
param=%WL '%P' '%T' %Q
User button:
Code: Select all
TOTALCMD#BAR#DATA
em_test_tc_params_files_folders
WCMICON2.DLL,21
tc params %WL %P %T %Q files and/or folders
0
-1
PowerShell script:
Code: Select all
$time = [diagnostics.stopwatch]::StartNew()
$path = [IO.DirectoryInfo]$pwd.path
if ($path){
'current and parent path'|Write-Host -f DarkGray;$path.FullName;$path|split-path}
''
if ($args){
'cmd=pwsh: Total Commander parameters breakdown...'|Write-Host -f Yellow
"param=%WL '%P' '%T' %Q [%Y|%y]"|Write-Host -f Gray
''
'%WL list file'|Write-Host -f Cyan
$list = [IO.FileInfo]$args[0];$list.Name
''
'%P source path'|Write-Host -f Cyan
$source = [IO.DirectoryInfo]$args[1];$source.FullName
''
'%T target path'|Write-Host -f Cyan
$target = [IO.DirectoryInfo]$args[2];$target.FullName}
''
if (-not($args)){$warning = 'no parameters have been passed'}
if ($args -and $list.length -le 2){$warning = '%WL list file is empty'}
if ($warning){$message = 'working directory $pwd'
'{0}, using {1} contents instead...' -f $warning,$message|Write-Host -f Yellow
$files = Get-ChildItem -path $path -force -file # add -recurse if needed
$folders = Get-ChildItem -path $path -force -directory}
if ($list.length -gt 2){$message = '%WL list file'
'{0} contents...' -f $message|Write-Host -f Yellow
$lines = [IO.File]::ReadLines($list)
$files = foreach ($line in $lines){
if ((Get-Item $line -force) -is [IO.FileInfo]){[IO.FileInfo]$line}}
$folders = foreach ($line in $lines){
if ((Get-Item $line -force) -is [IO.DirectoryInfo]){[IO.DirectoryInfo]$line}}
}
# working with files and folders
'{0} files in {1}' -f $files.count,$message|Write-Host -f Cyan
# do something with files: here, display full path
foreach ($file in $files){$file.FullName}
'{0} folders in {1}' -f $folders.count,$message|Write-Host -f Cyan
# do something with folders: here, display full path
foreach ($folder in $folders){$folder.FullName}
''
$time.Stop()
'{0} files and {1} folders in {2} for {3:mm\:ss\.fff}' -f
$files.count,$folders.count,$message,$time.Elapsed|Write-Host -f DarkCyan
'by {0}' -f $MyInvocation.MyCommand.Name
sleep -s 33
From the beginning, it wasn't intended for archives and the clipboard.
As the entry steps to make it work with those:
- Archives: I need to add %Z to the input parameters
- Clipboard: I need to put somewhere inside the script something like this: $clipboard = (Get-Clipboard)|foreach {$_}
- Then I would need to build new internal logic for the script to process the new data accordingly, respecting its specifics in different scenarios.
That will be relatively easy with the clipboard, since it's just another array of strings, where each string can be checked against the file system and properties.
And I've just made and tried a primitive standalone test script while writing this message, and it works with the cm_CopyFullNamesToClip perfectly:
test_clipboard_for_files_and_or_folders.ps1:
Code: Select all
$time = [diagnostics.stopwatch]::StartNew()
$clipboard = (Get-Clipboard)|foreach {$_}
$candidates_for_files_folders = $clipboard|foreach {if (Test-Path -Literal $_){$_}}
$files = $candidates_for_files_folders|foreach {if ((Get-Item $_ -force) -is [IO.FileInfo]){[IO.FileInfo]$_}}
$folders = $candidates_for_files_folders|foreach {if ((Get-Item $_ -force) -is [IO.DirectoryInfo]){[IO.DirectoryInfo]$_}}
# primitive output
'files:'|Write-Host -f Yellow
$files
$files.count ? 'files count {0}' -f $files.count : 'none'|Write-Host -f Cyan
$files|foreach{$_.FullName}|Write-Host -f Green
''
'folders:'|Write-Host -f Yellow
$folders
$folders.count ? 'folders count {0}' -f $folders.count : 'none'|Write-Host -f Cyan
$folders|foreach{$_.FullName}|Write-Host -f Green
''
# finalize
$time.Stop()
'{0:mm\:ss\.fff} by {1}' -f $time.Elapsed,$MyInvocation.MyCommand.Name
sleep -seconds 33
Note: you need PowerShell 7+ to utilise the ternary operator (
<condition> ? <if-true> : <if-false>) as in my script.
To do something with the strings that are the paths that lead inside the archives, it looks like I need to do a bit of research at first

For instance, the following command will look inside the archive, but the script doesn't know what to do with that yet (in the current edition, it just throws errors "Cannot find path 'e:\xternal\path\to\some\archive.zip\internal\path\to.something' because it does not exist").

User command (usercmd.ini):
Code: Select all
[em_test_tc_params_files_folders_Z]
cmd=pwsh -c "%commander_path%\Plugins\app\PowerShell\echoParamFiles.ps1"
param=%WL '%P' '%T' %Q %Z