Add files to ignore list with hotkey

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
woutermense
Junior Member
Junior Member
Posts: 8
Joined: 2015-08-19, 10:53 UTC

Add files to ignore list with hotkey

Post by *woutermense »

Hey I would like to map a hotkey which enables me to quickly add selected files to the ignore list. I've not found anything in the command list that would seem to do that. Is it possible?
User avatar
Stefan2
Power Member
Power Member
Posts: 4133
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Post by *Stefan2 »

Me think, yes, by a script

Lets think about:

--- selected files > TC param "%F" (Long file names without path, e.g. Long name.exe)

--- ignore list > "%Commander_Path%\tcignore.txt"

--- pseudo script > for each line in %F, echo line to tcignore.txt

--- Script > called from a user defined command in "%Commander_Path%\usercmd.ini"
[em_AddToIgnorelist]
cmd="path\to\script.cmd"
param="%F"

(or whole script is in usercmd.ini)
[em_AddToIgnorelist]
cmd=For /f eachline in ("%F") Do @echo line >> "%Commander_Path%\tcignore.txt"


--- A hotkey is assigned to that usercmd "em_AddToIgnorelist"



If you can't do that by yourself, we will provide you the solution.

 
woutermense
Junior Member
Junior Member
Posts: 8
Joined: 2015-08-19, 10:53 UTC

Post by *woutermense »

I thought I had it figured out, but I get "File not found" each time I try it. Not sure which file is meant there, but this is what I've done so far:

Tried with %Commander_Path% but the configuration files are located elsewhere so changed that to %$APPDATA%\GHISLER\

The script in usercmd.ini:
[em_AddToIgnorelist]
cmd=FOR /F "tokens=*" %%G IN (%F) DO ECHO %%G >> "%$APPDATA%\GHISLER\tcignore.txt"

And a mapped hotkey to it in wincmd.ini:
[Shortcuts]
A+DEL=em_AddToIgnorelist

I must be doing something wrong. That command is supposed to be like batch-script, right?
User avatar
Stefan2
Power Member
Power Member
Posts: 4133
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Post by *Stefan2 »

Good start, woutermense!

Yes, that is like DOS batch stuff.

First idea (nothing tested yet, have other things to do ;-) )

is to quote the "%F" part if you have space in your user name.

For that %F, %L and so on variables a temporarily file is created in your user temp folder (%temp%)



Perhaps I am wrong and you have to use cmd.exe too:
cmd=cmd /c
param=FOR /F "tokens=*" %%G IN ("%F") DO ECHO %%G >> "%$APPDATA%\GHISLER\tcignore.txt"


 
woutermense
Junior Member
Junior Member
Posts: 8
Joined: 2015-08-19, 10:53 UTC

Post by *woutermense »

I got the script correct to update the ignore list file. It will put any selection of files and folders in the list. The changes are effective after I restart TCMD. Think there's any way to make it read in the updated list immediately?

Anyway:

I used the cmd.exe way and to see what's going on I put &&PAUSE at the end.

"%F" put the filename of the generated temp file in the ignore list. So I kept just %F

Spaces are a thing in batch, so I got added spaces in the ignore list. I removed unnecessary spaces from the command to prevent it.

Final command:
[em_AddToIgnorelist]
cmd=cmd /c
param=FOR /F "tokens=*" %%G IN (%F) DO ECHO %%G>>"%%APPDATA%%\GHISLER\tcignore.txt"&&PAUSE

&&PAUSE should be removed after testing of course.
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

You can switch ignore list state twice in order to reread list file. Using TCFS2 you can use switch_ignore_list command (it will switch its state itself), or you can send cm_SwitchIgnoreList (2922) command to TC with other tools like TCMC.

It may have sense BTW to check if items to be added are already exist in list...
User avatar
Stefan2
Power Member
Power Member
Posts: 4133
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Post by *Stefan2 »

woutermense wrote:...

"%F" put the filename of the generated temp file in the ignore list. So I kept just %F
...
Ah, yes, I see.

So, for those who need quotes, use ( ' TYPE  "%F" ' )

param=FOR /F "tokens=*" %%G IN ('type "%F"') DO ECHO %%G>>"%%COMMANDER_PATH%%\tcignore.txt"&&PAUSE




 
User avatar
Stefan2
Power Member
Power Member
Posts: 4133
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Post by *Stefan2 »

woutermense wrote:...

Spaces are a thing in batch, so I got added spaces in the ignore list. I removed unnecessary spaces from the command to prevent it.

...
Ah, now I understand:

ECHO %%G>>
instead of
ECHO %%G >>


Well spotted, always a source of errors.


 
User avatar
Stefan2
Power Member
Power Member
Posts: 4133
Joined: 2007-09-13, 22:20 UTC
Location: Europa

PowerShell: Remove Duplicate Rows Lines From A Text file

Post by *Stefan2 »

MVV wrote:Y...

It may have sense BTW to check if items to be added are already exist in list...
Just for the record (and to find later again)

Have a file "RemoveDupsLines.ps1"

Code: Select all

#http://www.secretgeek.net/ps_duplicates
#Remove Duplicate Rows From A Text File Using Powershell... unsorted file, where order is important
#Call from DOS batch:       PowerShell .\RemoveDupsLines.ps1 """File to clean up.txt"""
$MyFile=$args[0];$hash=@{};(gc $MyFile)|%{if($hash.$_ -eq $null){$_};$hash.$_ =1} | Out-File -Encoding ASCII $MyFile


And add a line to above mentioned DOS Batch:

[em_AddToIgnorelist]
cmd="path\to\script.cmd"
param="%F"

Code: Select all

@ECHO OFF
FOR /F "tokens=*" %%G IN (' TYPE "%1" ') DO ECHO %%G>>"%%APPDATA%%\GHISLER\tcignore.txt"
PowerShell "%Commander_Path%\RemoveDupsLines.ps1 """%%APPDATA%%\GHISLER\tcignore.txt"""
Of course no need for DOS / PoSh mixup, but no time to correct that and write a whole PS script.



If interested, please test if that works (works for me in my tests)


 
Post Reply