Is there a way for me to use filename-passing codes (or variables which hold their result) with Rename PATTERN TO REGEXP? I’m starting with files with names such as Image.png.b64.txt, and am trying to use a multiple-step custom command to do several things, including two renaming steps:
rename "{filepath$|noext}.txt" pattern "*.b64.txt" to "*.b64"
Successfully renames Image.png.b64.txt as Image.png.b64
Successfully splits Image.png.b64 into multiple files up to 1000000 bytes in size, only at line breaks, with names Image.png.b64.00000, etc.
rename pattern "\{filepath\$\|noext\}\.(\d{1,5})" to "{filepath\$|noext}.\1.txt"
Hoped this would rename Image.png.b64.00000 as Image.png.b64.00000.txt, but doesn’t work. I’m figuring that either filename-passing codes can’t be mixed with regular expressions matching, or Rename PATTERN won’t operate on non-selected files when also using filename-passing codes in the arguments, or maybe the \ escape characters would need to be spliced into the result of {filepath$} beforehand as necessary then worked into the matching pattern somehow, or my usage of something else in the third command line is incorrect. Just wondering if this whole approach is a dead end and I need to look for another way.
I think the codes should work, but you wouldn't need to escape them, as the parsing is done before the argument gets given to the regex functions.
Try something like rename pattern "{filepath$|noext|escregexp}\.(\d{1,5}) etc. The escregexp modifier will cause any regex chars in the filename to be escaped automatically.
Unless I’m missing something here, I don’t think that’s going to work, since {filepath$} itself isn’t what’s being renamed in the second Rename operation. To recap and paraphrase from my first post:
Image.png.b64.txt (for example) is selected
Image.png.b64.txt gets renamed to Image.png.b64, and should remain selected by modifier @nodeselect
Image.png.b64 gets chopped into multiple pieces with names Image.png.b64.00000, etc.; Image.png.b64 should remain selected
Image.png.b64.00000, etc., (hopefully) get renamed as Image.png.b64.00000.txt, etc.; Image.png.b64 should remain selected
That’s the problem — there will often be other potential matches if I DON’T use {file} or {filepath}, which I don’t necessarily want matched. I only want files whose names are based on the original selected file(s) matched.
I’m trying to come up with a way to discern this, but does it matter for me that the original selected file(s) got renamed in the first step of the command? Does that change what {filepath$} in the second rename step (third command step) refers to, or does it still refer to the original selected filenames? I tried using {dlgchoose|{filepath}|Ok} or @confim:{filepath} between the second (Split) and third (second Rename) steps, but I ended up getting both dialogs before the Split command.
Most recent attempt variation:
@filesonly
@nodeselect
@leavedoswindowopen
@set filepath={filepath$|noext}
@set filepathre={filepath$|noext|escregexp}
dopusrt /acmd rename from "{$filepath}.txt" to "{$filepath}"
"C:\Program Files (x86)\Gnu Core Utils\bin\split.exe" -C 1000000 -d -a 5 "{$filepath}" "{$filepath}."
dopusrt /acmd rename from "{$filepathre}\.(\d{1,5})" pattern "{$filepathre}\.(\d{1,5})" to "{$filepathre}.\1.txt" REGEXP
Still doesn’t rename the perform the second rename (.b64.00000 to .b64.00000.txt, etc.).
The Rename FROM argument (for specifying which files are to be renamed, instead of using the current selection) can take wildcards but not regex, so that won't work.
(The PATTERN argument can work with wildcards, but not FROM.)
This all seems complex enough that using a script probably makes more sense. Then you have more control over which filenames are passed to what, and can have logic like "if file X exists then see if file f(X) also exists and do things to if" where f() is some kind of transformation on the filename.
With that in mind, I tried replacing from "{$filepathre}\.(\d{1,5})" with from "{$filepath}.*", as that would most likely take care of everything I’d need to throw at it without affecting any other files (full code as shown):
@filesonly
@nodeselect
@leavedoswindowopen
@set filepath={filepath$|noext}
@set filepathre={filepath$|noext|escregexp}
rename from "{$filepath}.txt" to "{$filepath}"
"C:\Program Files (x86)\Gnu Core Utils\bin\split.exe" -C 1000000 -d -a 5 "{$filepath}" "{$filepath}."
rename from "{$filepath}.*" pattern "{$filepathre}\.(\d{1,5})" to "{$filepathre}.\1.txt" REGEXP
But I get An error occurred renaming ‘{$filepath}.txt’: The system cannot find the file specified. (2)
Also tried using dopusrt /acmd, with all other code same as above:
[…]
dopusrt /acmd rename from "{$filepath}.txt" to "{$filepath}"
[…]
dopusrt /acmd rename from "{$filepath}\.*" pattern "{$filepathre}\.(\d{1,5})" to "{$filepathre}.\1.txt" REGEXP
But that opens the Advanced Rename dialog, twice, and does nothing else.
But as lxp kindly brought to my attention, FROM is supposed to change that behavior. The help file says (in the section on PATTERN): “Specifying the FROM argument as well will mean the command ignores the current file selection and applies the specified rename on all matching files.”
Well, I tried, anyway.
Sure, I’ll try anything once. About the equals = signs, though: I assume that’s just an optional convention that you like using? The examples in the help file’s Rename section don’t use them.
That part was already working for me, at least for my attempts in which the first Rename successfully completed, but guess what? You nailed it. The whole multi-step command worked correctly with one *.b64.txt file selected and two others present, and then with all three selected. Thanks, lxp.
To save myself work in the long run, of course. In combination with the other steps in this command, this workflow is something I’ve been doing manually on a regular basis, involving a fairly large amount of files, for a while. And I want the original *.b64.txt files to remain selected because my next step is to move, delete, or do something else with them.