Rename to a name including the folder

Discuss and share scripts and script files...
Post Reply
Oversemper
Posts: 6
Joined: 17 Sep 2015 11:50

Rename to a name including the folder

Post by Oversemper »

It is a shame for me to ask, as a person with PPH coding background, but one hour of researching Scripting Commands Reference did not allow me to get how to change my script:

Code: Select all

::rename "b", "EN"
which renames a file into EN.$current_extension, so it would rename a file into EN ($currentfoler).$current_extension.
So it have to be something like that:

Code: Select all

::rename "b", "EN ("$currentfoler")"
Please, help, I've read help for rename, renameitem commands a few time but there is no a single example which would somehow point out to how to include the current folder name.

highend
Posts: 14940
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Rename to a name including the folder

Post by highend »

You mean this?

Code: Select all

::rename "b", "EN (" . gpc(<curpath>, "base") . ")";
One of my scripts helped you out? Please donate via Paypal

Oversemper
Posts: 6
Joined: 17 Sep 2015 11:50

Re: Rename to a name including the folder

Post by Oversemper »

highend wrote: 09 Sep 2019 11:27 You mean this?

Code: Select all

::rename "b", "EN (" . gpc(<curpath>, "base") . ")";
That was quick. Thank you very much! This example must be included into the help file for the rename command.

highend
Posts: 14940
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Rename to a name including the folder

Post by highend »

No, it shouldn't. Why? E.g., don't use this method in a branch view with subfolders^^
One of my scripts helped you out? Please donate via Paypal

Oversemper
Posts: 6
Joined: 17 Sep 2015 11:50

Re: Rename to a name including the folder

Post by Oversemper »

Well. I think it should, and if it is necessary one can put * and write "don't use this method in a branch view with subfolders".

I just think that it is a basic thing for a renaming command (of a file explorer program) to use some part of the directory for renaming a file.

I attached screenshot how I use it, I select file and press button above "Ru" or "En" and file turns into RU ($current_Folder). Thanks to your script! But I would not figure it out how to code it, because the coding language for xyplorer is somewhat unintuitive and the help file lacks real-life examples. Really, one would think that there should be just a $current_folder variable, coz every file is inside some folder, and stuff like gpc(<curpath>, "base") is unintuitive. At least it is possible to add a remark in the rename command description, that gpc can be used for renaming... that would point me out to a right direction, but there is no any clue in the current help file.

I mean, I always read help files for figuring out the right coding, but this one was just absolutely unhelpful for me. And I coded a lot with Fortran and PPH, so I'm not a complete moron in coding (at least I think I'm not). Just look at the examples under the rename description in the help file:

Code: Select all

Examples
rename b, '*-<datem yyyymmdd>', p;
Appends the modified date to each of the selected items. With preview.
Note the single quotes around the date variable: This ensures that it is only resolved inside the rename procedure on a per-file basis. If it were double-quoted then all selected files would be appended the modified date of the currently focused item.
rename b, '*-<datem yyyymmdd>';
Appends the modified date to each of the selected items. Without preview.
rename , '*-<datem yyyymmdd>';
Same as above since the first parameter defaults to "b".
rename , '<dateexif yyyymmdd.hhnnss>-*', p;
Prepends the EXIF date to each of the selected items.
rename r, "\.html$ > .htm", p;
RegExp Rename replacing html extensions by htm.
rename s, "ü/ue";
Search & Replace Rename replacing all "ü" by "ue".
rename k, "0123456789", p;
Keep Particular Characters Rename, keeping only the numbers present in a filename.
rename e, "htm";
Change any current extension to "htm".
rename , "africa.png /e", p, "E:\TestFiles\asia.jpg";
Rename a specific file (here: E:\TestFiles\asia.jpg) to a hardcoded new name (africa.png), using itemlist and the /e switch (for renaming the extension as well).
rename b, <clipboard>, p, , 4;  //drop illegal characters
rename b, <clipboard>, p, , 4, "_"; //replace them with _
rename b, <clipboard>, p, , 12, "_"; //same as before with increment
Rename by list:
rename "l";                                 //dialog is pre-filled with current item names
rename "l", "Don2017.jpg|Don2018.jpg";      //dialog is skipped; no preview
rename "l", "Don2017.jpg|Don2018.jpg", "p"; //dialog is skipped; preview
And which example should allow me to figure out how to include folder name into the renaming?
To see the attached files, you need to log into the forum.

highend
Posts: 14940
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Rename to a name including the folder

Post by highend »

Code: Select all

::rename "b", "EN (<curfolder>)";
You could use this as well. It would only require to read the chapter about variables :biggrin:
But again, this is not applicable for every scenario...
One of my scripts helped you out? Please donate via Paypal

Oversemper
Posts: 6
Joined: 17 Sep 2015 11:50

Re: Rename to a name including the folder

Post by Oversemper »

This one is much more subtle)) Thank you!

Post Reply