Rename only part of a file on certain conditions

Discuss and share scripts and script files...
kiwichick
Posts: 557
Joined: 08 Aug 2012 04:14
Location: Pahiatua, New Zealand

Re: Rename only part of a file on certain conditions

Post by kiwichick »

highend wrote: 24 Apr 2022 10:10 Ofc it doesn't work.

Do you think that feeding the full list of selected items as source into EACH LOOP does make any sense? No, it doesn't.

Use renameitem() with the correct variables^^
I always appreciate your willingness to help but sometimes it feels like you are being deliberately obscure. You make comments and ask questions that seem aimed at making someone feel foolish for not knowing what to do and not understanding what's been provided. Having to go round and round with small bits of code and vague clues about what what to do next is sometimes more hindrance than help, and it's darn confusing. I'm giving up on this particular bit of code because it's doing my head in.
Windows 10 Pro 22H2

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

Re: Rename only part of a file on certain conditions

Post by highend »

Vague? I'm utterly precise.

small bits and code? Because the main code has already been posted and even the help file has several examples how to loop over selected items^^

The shortest version is this:

Code: Select all

    foreach($item, <get SelectedItemsPathNames>, <crlf>, "e") {
        $base    = (exists($item) == 1) ? gpc($item, "base") : gpc($item, "file");
        $newName = regexreplace($base, "\.(?![0-9])", " ");
        renameitem($newName, $item, 1);
    }
One of my scripts helped you out? Please donate via Paypal

chumbo
Posts: 243
Joined: 04 Jan 2015 15:20

Re: Rename only part of a file on certain conditions

Post by chumbo »

I've been secretly watching in hope that the 'secret sauce' would finally be revealed (thx kiwichick for reviving this)! So thx highend for doing so because this is WAY above my head! I was naive to think I could tackle scripting something like this at my current level.
Works great! :D

kiwichick
Posts: 557
Joined: 08 Aug 2012 04:14
Location: Pahiatua, New Zealand

Re: Rename only part of a file on certain conditions

Post by kiwichick »

chumbo wrote: 24 Apr 2022 11:01 I've been secretly watching in hope that the 'secret sauce' would finally be revealed (thx kiwichick for reviving this)! So thx highend for doing so because this is WAY above my head! I was naive to think I could tackle scripting something like this at my current level.
Works great! :D
You're welcome :D
Windows 10 Pro 22H2

kiwichick
Posts: 557
Joined: 08 Aug 2012 04:14
Location: Pahiatua, New Zealand

Re: Rename only part of a file on certain conditions

Post by kiwichick »

highend wrote: 24 Apr 2022 10:49 I'm utterly precise.
Clearly your idea of being precise differs to that of some people. Thank you very much for supplying the code required.
Windows 10 Pro 22H2

Post Reply