New+ Support for variables in template filenames (35287)
Summary of the Pull Request
Added support for variables in template filenames
Variables supported includes
- Date and time component variables, such as
$YYYY,$YY,$MM,$DD, - using the same syntax and implementation as in PowerRename $PARENT_FOLDER_NAME- will replace variable with the name of the parent folder%environment-variable%- will replace variable with the value of the corresponding environment variable
Example:
Template filename:
$YYYY-$MM-%DD, $hh - $PARENT_FOLDER_NAME by %USERNAME%
Filename on create becomes:
2025-01-25, 02 - PowerShell project by cgaarden
PR Checklist
- [x] Closes: #35287
- [x] Also closes:
- [x] **35287
- [x] **35984
- [x] **36615
- [x] **36425
- [x] Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
- [n/a] Tests: Added/updated and all pass
- [x] Localization: All end user facing strings can be localized
- [n/a] Dev docs: Added/updated
- [n/a] New binaries: Added on the required places
- [n/a] JSON for signing for new binaries
- [n/a] WXS for installer for new binaries and localization folder
- [n/a] YML for CI pipeline for new test projects
- [n/a] YML for signed pipeline
- [x] Documentation updated: If checked, please file a pull request on our docs repo and link it here: #5285 https://github.com/MicrosoftDocs/windows-dev-docs/pull/5285
Detailed Description of the Pull Request / Additional comments
SHFileOperation API related
Still using SHFileOperation API - may change this in a future PR as the current implementation requires iterating through files multiple times (not really that impactful unless a template folder contains 100s+ of files/subfolders Fixed an issue on ARM64 when depending on SHFileOperation to provide filename remapping
Minor refactoring
To help with support the variable support
Minor exception handling logic
To help get information on where New+ menu isn't being displayed
Validation Steps Performed
- Windows 10 clean install, with lots of different template permutations
- Windows 11 clean and update install, with lots of different template permutations
- Windows 11 ARM64 and x64, with lots of different template permutations
- Template folders with subitems with multiple variables within filenames
- Template items starting with digits and spaces, e.g. 13. $YYYY-$MM-$DD PTA meeting minutes and actions
- Rename mode is entered as expected for files and folder based templates, also when creating template with same name multiple times (x) in Arabic script
- Validated that GPO ConfigureEnabledUtilityNewPlus, NewPlusHideTemplateFilenameExtension, NewPlusReplaceVariablesInTemplateFilenames are working as intended
Example template folder + corresponding context menu
Example of project including subitems
New+ settings
(debug)
New+ related GPO policies
@check-spelling-bot Report
:red_circle: Please review
See the :open_file_folder: files view, the :scroll:action log, or :memo: job summary for details.
Unrecognized words (1)
Examaples
These words are not needed and should be removed
AMPROPERTY AMPROPSETID Breadcrumb CDEF comdef ddf devenum DEVMON DEVSOURCE DGR DIIRFLAG dshow DVH DVHD DVSD DVSL EData ERole fdw FILEINFOSIG Filtergraph Filterx HCERTSTORE IKs iljxck IYUV KSPROPERTY lcb ldx lld LONGLONG LTRB majortype makecab MEDIASUBTYPE mediatype mfplat mic mjpg Msimg msiquery ORAW outpin overlaywindow PAUDIO PINDIR Pnp ppmt previouscamera PROPBAG propvarutil reencode reencoded REFGUID REGFILTER REGFILTERPINS REGPINTYPES regsvr shmem SHNAMEMAPPING sizeread stl strsafe strutil subquery SYNCMFT TMPVAR vcdl vdi vid VIDCAP VIDEOINFOHEADER vih WANTMAPPINGHANDLE webcam wistd WVCTo accept these unrecognized words as correct and remove the previously acknowledged and now absent words, you could run the following commands
... in a clone of the [email protected]:cgaarden/PowerToys.git repository
on the New+feature-35287-support-for-variables-in-templates branch (:information_source: how do I use this?):
curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/v0.0.24/apply.pl' |
perl - 'https://github.com/microsoft/PowerToys/actions/runs/12969083641/attempts/1'
If the flagged items are :exploding_head: false positives
If items relate to a ...
-
binary file (or some other file you wouldn't want to check at all).
Please add a file path to the
excludes.txtfile matching the containing file.File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.
^refers to the file's path from the root of the repository, so^README\.md$would exclude README.md (on whichever branch you're using). -
well-formed pattern.
If you can write a pattern that would match it, try adding it to the
patterns.txtfile.Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.
Note that patterns can't match multiline strings.
Has conflicts
Has conflicts
Recent conflicts with GPO settings are now resolved again
/azp run
Azure Pipelines successfully started running 1 pipeline(s).
/azp run
Azure Pipelines successfully started running 1 pipeline(s).
Hi @cgaarden , Thank you for opening the PR.
I think the code looks good and I like the approach. I tried to use the docs and not everything worked for me:
"$YYYY-$MM-%DD, $hh $mm $ss - $PARENT_FOLDER_NAME by %USERNAME%" I tried this and saw that there's a error in
%DDinstead of$DD, but still couldn't get $PARENT_FOLDER_NAME to work for me. I left some smaller comments a bit before writing this review. Thank you :)
Re %DD Fixed %DD in the documentation.
Re $PARENT_FOLDER_NAME $PARENT_FOLDER_NAME only works in subfolders, e.g. Templates\Key project$PARENT_FOLDER_NAME intro.md
will expand to
and doesn't work at the "root" of the template folder, e.g. Templates$PARENT_FOLDER_NAME intro.md
Updated the documentation to call this out.
Thank you!
Thank you @jaimecbernardo for review and feedback!
I've updated the PR and also the documentation PR.
Thank you!
/azp run
Azure Pipelines successfully started running 1 pipeline(s).
/azp run
Azure Pipelines successfully started running 1 pipeline(s).
Hi Christian. Gave it another try, but seems like the new setting doesn't do anything. Variables will be replaced whether that setting is off or on. Can you please take a look? Thank you!
Thank you Jaime for having yet another look.
I fixed the issue and fixed a similar issue that I completely missed for optionally hiding file extensions.
Thank you for the feedback and patience with my mistakes here.
/azp run
Azure Pipelines successfully started running 1 pipeline(s).