Script request: Apply tags to selected folders and its subfolders

Discuss and share scripts and script files...
karimmaster101
Posts: 158
Joined: 20 May 2011 14:34

Script request: Apply tags to selected folders and its subfolders

Post by karimmaster101 »

Hello, I need a script to apply a tag to selected folders and its subfolders, it should goes as deep as it could.
It will be great too if it has an option to apply tags to files and folders, or folders only.

Thanks in advance

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

Re: Script request: Apply tags to selected folders and its subfolders

Post by highend »

Options:
D = Directories only
D+F + Directories and files

You switch options by clicking on the "Option: <current type>" menu entry!

Code: Select all

"_Initialize"
    perm $P_TagOptions;
    if (!$P_TagOptions) { $P_TagOptions = "D"; }

"Option: $P_TagOptions"
    if ($P_TagOptions == "D") { $P_TagOptions = "D+F"; }
    elseif ($P_TagOptions == "D+F") { $P_TagOptions = "D"; }
    else { $P_TagOptions = "D"; }
    load "*", "Apply tag", "s";

"Apply tag"
    $notes = ($P_TagOptions == "D") ? "Directories only": "Directories AND files";
    $tag = input("Enter the tag to apply", "Tags will apply to:<crlf 2>$notes");
    if (!$tag) { status "No tag entered, aborted", , "alert"; end true; }

    $selItems = get("SelectedItemsPathNames");
    // Directories only
    if ($P_TagOptions == "D") {
        $selFolders = GetFoldersOnly($selItems, <crlf>, <crlf>);
        $items = formatlist($selFolders . <crlf> . quicksearch("/d", $selFolders), "sed", <crlf>);
    // Directories and files
    } elseif ($P_TagOptions == "D+F") {
        $selFolders = GetFoldersOnly($selItems, <crlf>, <crlf>);
        $selFiles = formatlist($selItems, "sedF", <crlf>, "!$selFolders");
        $items = formatlist($selFiles . <crlf> . $selFolders . <crlf> . quicksearch("", $selFolders), "sed", <crlf>);
    }

    if ($items) {
        tagitems("tags", $tag, $items);
        status "All items tagged...", , "ready";
    }

function GetFoldersOnly($items, $inSep="|", $outSep="|") {
    $list = "";
    foreach($item, $items, $inSep, "e") {
        if (exists($item) == 2) { $list = $list . $item . $outSep; }
    }
    return formatlist($list, "sed", $outSep);
}
One of my scripts helped you out? Please donate via Paypal


karimmaster101
Posts: 158
Joined: 20 May 2011 14:34

Re: Script request: Apply tags to selected folders and its subfolders

Post by karimmaster101 »

If you wouldn't mind I have more requests:
- I need a script to remove all (labels) from selected folders contents (files and folders). I appreciate if you could explain it so I could modify it to apply it on comments or tags
- Another script to remove all (labels) from selected folders contents (Folders Only).

In this case I need scripts to be separated to be able to assign them with keyboard shortcuts.

Thanks in advance :D

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

Re: Script request: Apply tags to selected folders and its subfolders

Post by highend »

The script already contains all necessary parts to accomplish these things.
You only need to rearrange it / rip out unnecessary stuff if you want to split it for different functionality
tagitems() is able to remove tags / labels / comments as well
One of my scripts helped you out? Please donate via Paypal

karimmaster101
Posts: 158
Joined: 20 May 2011 14:34

Re: Script request: Apply tags to selected folders and its subfolders

Post by karimmaster101 »

highend wrote:The script already contains all necessary parts to accomplish these things.
You only need to rearrange it / rip out unnecessary stuff if you want to split it for different functionality
tagitems() is able to remove tags / labels / comments as well

I tried a lot of things by now, Finally I get it worked on folders but unfortunately it didn't work on both of folders and files.

This is the script I used to target folders only

Code: Select all

"Apply tag"
    $notes = ($P_TagOptions == "D") ? "Directories only": "Directories AND files";
    if (!$tag) { status "No tag entered, aborted", , "alert"; end true; }

    $selItems = get("SelectedItemsPathNames");
    // Directories only
    if ($P_TagOptions == "D") {
        $selFolders = GetFoldersOnly($selItems, <crlf>, <crlf>);
        $items = formatlist($selFolders . <crlf> . quicksearch("/d", $selFolders), "sed", <crlf>);

    if ($items) {
        tagitems("label", "", $items);
        status "All items tagged...", , "ready";
    }

function GetFoldersOnly($items, $inSep="|", $outSep="|") {
    $list = "";
    foreach($item, $items, $inSep, "e") {
        if (exists($item) == 2) { $list = $list . $item . $outSep; }
    }
    return formatlist($list, "sed", $outSep);
}
I tried the following script to target both files and folders but it didn't work

Code: Select all

"Option: $P_TagOptions"
    if ($P_TagOptions == "D") { $P_TagOptions = "D+F"; }
    elseif ($P_TagOptions == "D+F") { $P_TagOptions = "D"; }
    else { $P_TagOptions = "D"; }

"Apply tag"
    $notes = ($P_TagOptions == "D") ? "Directories only": "Directories AND files";
    if (!$tag) { status "No tag entered, aborted", , "alert"; end true; }

    $selItems = get("SelectedItemsPathNames");
    // Directories only
    if ($P_TagOptions == "D") {
        $selFolders = GetFoldersOnly($selItems, <crlf>, <crlf>);
        $items = formatlist($selFolders . <crlf> . quicksearch("/d", $selFolders), "sed", <crlf>);
    // Directories and files
    } elseif ($P_TagOptions == "D+F") {
        $selFolders = GetFoldersOnly($selItems, <crlf>, <crlf>);
        $selFiles = formatlist($selItems, "sedF", <crlf>, "!$selFolders");
        $items = formatlist($selFiles . <crlf> . $selFolders . <crlf> . quicksearch("", $selFolders), "sed", <crlf>);
    }

    if ($items) {
        tagitems("label", "", $items);
        status "All items tagged...", , "ready";
    }

function GetFoldersOnly($items, $inSep="|", $outSep="|") {
    $list = "";
    foreach($item, $items, $inSep, "e") {
        if (exists($item) == 2) { $list = $list . $item . $outSep; }
    }
    return formatlist($list, "sed", $outSep);
}

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

Re: Script request: Apply tags to selected folders and its subfolders

Post by highend »

Without any options to change, unlabeling files and folders is simply...

Code: Select all

    $selItems = get("SelectedItemsPathNames");
    $selFolders = GetFoldersOnly($selItems, <crlf>, <crlf>);
    $selFiles = formatlist($selItems, "sedF", <crlf>, "!$selFolders");
    $items = formatlist($selFiles . <crlf> . $selFolders . <crlf> . quicksearch("", $selFolders), "sed", <crlf>);

    if ($items) {
        tagitems("label", "", $items);
        status "All items untagged...", , "ready";
    }
    
function GetFoldersOnly($items, $inSep="|", $outSep="|") {
    $list = "";
    foreach($item, $items, $inSep, "e") {
        if (exists($item) == 2) { $list = $list . $item . $outSep; }
    }
    return formatlist($list, "sed", $outSep);
}
One of my scripts helped you out? Please donate via Paypal

karimmaster101
Posts: 158
Joined: 20 May 2011 14:34

Re: Script request: Apply tags to selected folders and its subfolders

Post by karimmaster101 »

Thanks for the new script, it looks like what I need except I got this message "Call to undefined function: getfoldersonly" every time I tried to run it.
Am I doing anything wrong?

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

Re: Script request: Apply tags to selected folders and its subfolders

Post by highend »

You didn't add the function ... part?
One of my scripts helped you out? Please donate via Paypal

karimmaster101
Posts: 158
Joined: 20 May 2011 14:34

Re: Script request: Apply tags to selected folders and its subfolders

Post by karimmaster101 »

highend wrote:You didn't add the function ... part?
No, I didn't. I add it now and it is working ......... Thank you very much

karimmaster101
Posts: 158
Joined: 20 May 2011 14:34

Re: Script request: Apply tags to selected folders and its subfolders

Post by karimmaster101 »

Hello all,
Now, I'm using the following script to remove any label from selected folders and sub-folders.

Code: Select all

"Apply tag"
    $notes = ($P_TagOptions == "D") ? "Directories only": "Directories AND files";

    if (!$tag) { status "No tag entered, aborted", , "alert"; end true; }

    $selItems = get("SelectedItemsPathNames");
    // Directories only
    if ($P_TagOptions == "D") {
        $selFolders = GetFoldersOnly($selItems, <crlf>, <crlf>);
        $items = formatlist($selFolders . <crlf> . quicksearch("lbl:** /d", $selFolders), "sed", <crlf>);

    if ($items) {
        tagitems("label", "", $items);
        status "All items tagged...", , "ready";
    }

function GetFoldersOnly($items, $inSep="|", $outSep="|") {
    $list = "";
    foreach($item, $items, $inSep, "e") {
        if (exists($item) == 2) { $list = $list . $item . $outSep; }
    }
    return formatlist($list, "sed", $outSep);
}
My question here, how could I modify it to remove labels from the sub-folders (as deep as it goes) of the selected folders only.

Thanks in advance

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

Re: Script request: Apply tags to selected folders and its subfolders

Post by highend »

I don't understand...

You mean all existing labels from all subfolders but not the label from the selected folders?
One of my scripts helped you out? Please donate via Paypal

karimmaster101
Posts: 158
Joined: 20 May 2011 14:34

Re: Script request: Apply tags to selected folders and its subfolders

Post by karimmaster101 »

highend wrote:I don't understand...

You mean all existing labels from all subfolders but not the label from the selected folders?
Lets assume I am selecting
C:\folder1
C:\folder2
C:\folder3
I want to set labels for all sub-folders in those folders but not them. so, folder1, folder2, and folder3 labels shouldn't be changed while its contents will.

Note: I am hoping that it works whether I am selecting the folders or using the current path
For example in this case, I will not select any folder, but I am in C:\example\ directory
I expect that it will leave the folders in the current path untouched while changing itssub-folders
Unchanged
C:\example\folder1
C:\example\folder2
C:\example\folder3
I hope that I explained it clearly. Thanks in advance

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

Re: Script request: Apply tags to selected folders and its subfolders

Post by highend »

Code: Select all

"Apply tag"
    $notes = ($P_TagOptions == "D") ? "Directories only": "Directories AND files";

    if (!$tag) { status "No tag entered, aborted", , "alert"; end true; }

    $selItems = get("SelectedItemsPathNames");
    // Directories only
    if ($P_TagOptions == "D") {
        $selFolders = GetFoldersOnly($selItems, <crlf>, <crlf>);
        // Selected folders
        if ($selFolders) {
            $items = formatlist(quicksearch("lbl:** /d", $selFolders), "sed", <crlf>);
        // No selected folders, use folders in <curpath>
        } else {
            $items = formatlist(quicksearch("lbl:** /d", listfolder(<curpath>, , 2, <crlf>)), "sed", <crlf>);
        }
    }

    if ($items) {
        tagitems("label", "", $items);
        status "All items tagged...", , "ready";
    }

One of my scripts helped you out? Please donate via Paypal

karimmaster101
Posts: 158
Joined: 20 May 2011 14:34

Re: Script request: Apply tags to selected folders and its subfolders

Post by karimmaster101 »

highend wrote:

Code: Select all

"Apply tag"
    $notes = ($P_TagOptions == "D") ? "Directories only": "Directories AND files";

    if (!$tag) { status "No tag entered, aborted", , "alert"; end true; }

    $selItems = get("SelectedItemsPathNames");
    // Directories only
    if ($P_TagOptions == "D") {
        $selFolders = GetFoldersOnly($selItems, <crlf>, <crlf>);
        // Selected folders
        if ($selFolders) {
            $items = formatlist(quicksearch("lbl:** /d", $selFolders), "sed", <crlf>);
        // No selected folders, use folders in <curpath>
        } else {
            $items = formatlist(quicksearch("lbl:** /d", listfolder(<curpath>, , 2, <crlf>)), "sed", <crlf>);
        }
    }

    if ($items) {
        tagitems("label", "", $items);
        status "All items tagged...", , "ready";
    }


I don't know what's wrong, but unfortunately it doesn't work. It shows that"All items tagged..." but no label changed at all
Last edited by karimmaster101 on 08 Oct 2017 22:00, edited 1 time in total.

Post Reply