EliziumNet / RexFs

Regular expression based Bulk File/Directory renamer
MIT License
4 stars 2 forks source link

Rename-Many: Add special variables #5

Open plastikfan opened 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 2 years ago

Special values will be denoted by the use of \<>. Variables must always be applicable, ie never not defined for an item; eg every fs-item has a parent directory so parent directory name is always defined. Although having said this, if an item is the root path, can't get the parent of that; but this is a silly edge case, which must be handled.

This might have to be implemented as a transform.