Name down

Discuss and share scripts and script files...
Post Reply
admin
Site Admin
Posts: 60558
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Name down

Post by admin »

I needed this today, it's a bit special but maybe you have a use for it, too.

Use case: I often download images and accompanying text bits from websites, both by drag and drop. So I have these files side by side in my drop target folder:

Code: Select all

knife-throwing-ex05.jpg
DroppedText-20160621.txt
Now I want a clear connection between the two files. They should have the same name:

Code: Select all

knife-throwing-ex05.jpg
knife-throwing-ex05.txt
This script will do that in one click when the files are listed one after the other and the source file (the name to be used) is focused:

Code: Select all

// 20160621: name the item after the focused item like the focused item
  $focpos = get("focusedpos");
  $focitem = get("item", , $focpos);
  $nextitem = get("item", , $focpos + 1);
  if ($focitem) {
    $focbase = gpc($focitem, "base");
    $newname = renameitem($focbase, $nextitem, , "-01");
    if ($newname) {
      status "rename done, new name: " . gpc($newname, "file");
    } else {
      status "rename failed, old name: " . gpc($nextitem, "file"), , "alert";
    }
  }
Just a quickie that covers my needs so far.

LittleBiG
Posts: 1846
Joined: 08 Apr 2011 12:57
Location: Win10x64

Re: Name down

Post by LittleBiG »

Yes, something similar was my very first script, to match the subtitle file name to the movie file name. Mine may be even simpler.

Code: Select all

"Name matching|c:\windows\system32\shell32.dll / 250"
  if (<curitem> != "" AND <curitemprev> != "")
  { call renameitem("<get curitemprev base>", , 1)
  } else {
    status "Missing selection", , "alert"
  }
Edit: the source topic is viewtopic.php?f=5&t=9481

xy123
Posts: 142
Joined: 17 Sep 2017 11:46

Re: Name down

Post by xy123 »

LittleBiG wrote: 25 Jun 2016 18:07 Yes, something similar was my very first script, to match the subtitle file name to the movie file name.

Code: Select all

"Name matching|c:\windows\system32\shell32.dll / 250"
  if (<curitem> != "" AND <curitemprev> != "")
  { call renameitem("<get curitemprev base>", , 1)
  } else {
    status "Missing selection", , "alert"
  }
Doesn't work anymore. Anyone knows how to fix this?

sshot-1.png
sshot-1.png (34.06 KiB) Viewed 1915 times

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

Re: Name down

Post by highend »

Do you mind posting which items you have selected and what your <curitemprev> is?
One of my scripts helped you out? Please donate via Paypal

xy123
Posts: 142
Joined: 17 Sep 2017 11:46

Re: Name down

Post by xy123 »

Only 2 files in this folder:
sshot-2.png
sshot-2.png (3.64 KiB) Viewed 1911 times

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

Re: Name down

Post by highend »

Incomplete answer *sigh*

Code: Select all

    if (<curitem> != "" AND <curitemprev> != "") {
        renameitem("<get curitemprev base>", , 1+16);
    } else { status "Missing selection", , "alert"; }
One of my scripts helped you out? Please donate via Paypal

xy123
Posts: 142
Joined: 17 Sep 2017 11:46

Re: Name down

Post by xy123 »

Thank you, highend. Sorry, I don't know why I tested it with same extensions, so stupid.

Malarki
Posts: 109
Joined: 03 Dec 2019 02:51

Re: Name down

Post by Malarki »

It looks like flags '1+16' is a mistake, and it should be '1'.

Source names

bbbb.mp4
yyyy.srt

When I select the pair of them, and run the script with '1+16' flags, I get:

bbbb-$$01.srt
bbbb.mp4

If I revert to the previous flag of '1' it works properly, giving:

bbbb.mp4
bbbb.srt

Malarki
Posts: 109
Joined: 03 Dec 2019 02:51

Re: Name down

Post by Malarki »

Added minor safety / sanity check, for two files only:

Code: Select all

if get("CountSelected") == 2 {
  if (<curitem> != "" AND <curitemprev> != "") {
    renameitem("<get curitemprev base>", , 1);
  } else { status "Missing selection", , "alert"; }
 } else { status "Select two files, only", , "alert"; }

[couldn't format previous post; page permissions problem now fixed]

Post Reply