EliziumNet / Loopz

PowerShell iteration utilities with additional tools like the Parameter Set Tools
https://eliziumnet.github.io/Loopz/
MIT License
3 stars 0 forks source link

Rename-Many: Add special variables #109

Closed plastikfan closed 3 years ago

plastikfan commented 3 years ago

For example if the user wanted to rename a collection of files in terms of the parent directory, they should be able to use a special variable inside $With/$Paste to reference that item: For these varibles, let's use _ and CAPITAL letters. This will distinguish from named group references.

We could also have a field mapper. For example, lets say files contain dates, we might decide we'd like to map month numbers tomonth names. So insert a capture, the user would do this:

-Pattern '(?\d{2})-(?\d{2})-(?\d{4})' -Paste/With '(${year}-${mon}-${day})'

with a mapper we could do something like

-Pattern '(?\d{2})-(?\d{2})-(?\d{4})' -Paste/With '(${year}-*{mon:fn}-${day})'

where the * means map that field. So which map function? The :fn specifies the mapper function. To implement this, we'd need to add a Mappers parameter that is a hashtable, mapping function names (the fn) to script-block.

Since the use of a hashtable would be a common pattern, we could use alterative notation to simply look up the value in a user defined hashtable.

-Paste/With '(${year}-*{mon@lookup}-${day})'

The @ means look up the value in a hash table identified by 'lookup'. We would need to introduce a new variable -Lookup

All this functionality would typically be used by developers writing new functions that sit atop Rename-Many.

plastikfan commented 3 years ago

Issue moved to BulkRenamer as https://github.com/EliziumNet/BulkRenamer/issues/5