Rename Using Multiple Input variables

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
nicholascueto
Posts: 22
Joined: 02 Dec 2020 01:35

Rename Using Multiple Input variables

Post by nicholascueto »

Searched around for a bit but didn't find an answer. This should be simple!

I just need a script to rename files but accept more than one input for the name. Here's what I have but it's not working.

Code: Select all

$name = input("Filename", "File Name", "NoName"); $type = input("File Type", "Social, Other, etc.", "Social"); renameitem("<date mm-dd-yy>_$type_$name");
Output is as follows.
20-04-22_$type_Test
Bonus points if you can make it create a variable from the last word of a directory, 2 or 3 directories up, depending on whether that directory is a number.

ie. (THIS IS NOT CODE, just meant to help explain)

if ../../dir name != int:
$dirname = ../../dir name
$split_dirname = name
$filetype = name

else if ../../dir name == int:
$dirname = ../../../dir name
$split_dirname = name
$filetype = name

If only this was coded in Python! I could make that work.... :veryconfused:

Thank you for your help!

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

Re: Rename Using Multiple Input variables

Post by highend »

Code: Select all

$name = input("Filename", "File Name", "NoName");
    $type = input("File Type", "Social, Other, etc.", "Social");
    renameitem("<date mm-dd-yy>" . "_" . $type . "_" . $name);
and regarding your explanation:

If a dir name is an int, there would be nothing to split...

If it only begins with an int...

getpathcomponent(<curpath>, "component", -3);

and a regexmatches() to test if the first part is an int

and a gettoken() to get the last part of it...
One of my scripts helped you out? Please donate via Paypal

nicholascueto
Posts: 22
Joined: 02 Dec 2020 01:35

Re: Rename Using Multiple Input variables

Post by nicholascueto »

Thank you! So I needed to concatenate. That makes so much sense.

Secondly. I understand why you misunderstood. It's a terrible way to explain what was going on. The idea with the "else if" block was that if the directory name was an int ( or evaluated to an int, if it works like python ie. int("5") evaluates to 5 ) then it would traverse three directories up instead of two directories.

The directory up from that would be a dir with the format "Dir Name" and thus could be split.

To reiterate:

if .. / .. / == int:
$dirname = .. / .. / .. /dir name
$split_dirname = name

Hope that makes sense!

nicholascueto
Posts: 22
Joined: 02 Dec 2020 01:35

Re: Rename Using Multiple Input variables

Post by nicholascueto »

Thanks again for the help!

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

Re: Rename Using Multiple Input variables

Post by highend »

Code: Select all

$name  = input("Filename", "File Name", "NoName");
    $twoUp = gpc(<curpath>, "component", -3);
    if (!regexmatches($twoUp, "^[0-9]+?$")) {
        $type = gettoken($twoUp, -1, " ", "t");
    } else {
        $threeUp = gpc(<curpath>, "component", -4);
        $type    = gettoken($threeUp, -1, " ", "t");
    }
    renameitem("<date mm-dd-yy>" . "_" . $type . "_" . $name);
One of my scripts helped you out? Please donate via Paypal

Post Reply