Page 1 of 1

Name down

Posted: 21 Jun 2016 17:09
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.

Re: Name down

Posted: 25 Jun 2016 18:07
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

Re: Name down

Posted: 23 Mar 2022 13:34
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

Re: Name down

Posted: 23 Mar 2022 13:42
by highend
Do you mind posting which items you have selected and what your <curitemprev> is?

Re: Name down

Posted: 23 Mar 2022 13:45
by xy123
Only 2 files in this folder:
sshot-2.png

Re: Name down

Posted: 23 Mar 2022 13:50
by highend
Incomplete answer *sigh*

Code: Select all

    if (<curitem> != "" AND <curitemprev> != "") {
        renameitem("<get curitemprev base>", , 1+16);
    } else { status "Missing selection", , "alert"; }

Re: Name down

Posted: 23 Mar 2022 13:59
by xy123
Thank you, highend. Sorry, I don't know why I tested it with same extensions, so stupid.

Re: Name down

Posted: 03 Apr 2022 22:45
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

Re: Name down

Posted: 03 Apr 2022 23:03
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]