Command Number for "Copy Containing Folder(s)"?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Jeff Bellune
Posts: 284
Joined: 13 Dec 2007 12:55

Command Number for "Copy Containing Folder(s)"?

Post by Jeff Bellune »

What is the Command Number for the Context Menu item, "Copy Containing Folder(s)", please? It doesn't show up under Help>List All Commands...

I'd like to use it in a script.

Thanks,
Jeff

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Command Number for "Copy Containing Folder(s)"?

Post by bdeshi »

Well, that command doesn't have ID.
But you can create a script counterpart and give that your own ID!
First run this script, enter this in the addressbar and press enter.

Code: Select all

::#656; //User Commands --> Manage Commands
in the opened User Command Manager, select Run Script, Click on New, select Add New Command.
UsrCmds.gif
in the caption box: "Copy Containing Folders(s) [scripted]" (you can of course enter whatever you wish)
in the Script box: click edit button and paste the following script:

Code: Select all

//Copy Containing Folder(s) [script]
 $selection = get(SelectedItemsPathNames, '|'); //store pipe-separated fullpath of all selected items
 $copydata=; //create an empty variable to store list of to-be-copied folders
 foreach ($item, $selection, '|'){
  //for each |-separated $item in $selection...
  //get $item's parent path, and add it to $copydata with a | in between
  $copydata = $copydata.'|'.getpathcomponent($item, path); 
 }
 $copydata = trim($copydata, '|', L); //trim extra | at the beginning
 if ($copydata != ''){
  //if copydata is not empty...
  copy $copydata; //copy it's contents
 }
[/size]It copies the parent folder of selected items to clipboard.

Now here's the brilliant part. Look at the bottom of the ^ image ^, #1400. Whatever number you get here is the command ID for this custom command you just created. Which just happens to mimic "Copy Containing Folder(s)" and could probably be used instead, especially since that ctx menu item has no cID... :wink:
To see the attached files, you need to log into the forum.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

Jeff Bellune
Posts: 284
Joined: 13 Dec 2007 12:55

Re: Command Number for "Copy Containing Folder(s)"?

Post by Jeff Bellune »

Thank you and well done! The UDC works perfectly!

I'm currently trying to write my own script to do a custom search for folders that *don't* contain certain files. Block commands, foreach and if appear to be necessary. Scary stuff! :shock:

<joke>I can't believe that some of you people think this stuff is fun.</joke>

Cheers,
Jeff

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

Re: Command Number for "Copy Containing Folder(s)"?

Post by highend »

Something like this?

Code: Select all

    $excludedFiles = "AddonCopy.xys|COMMIT_EDITMSG";
    $folders = folderreport("dirs", "r", "<curpath>", "r", , "<crlf>");
    $files = folderreport("files", "r", "<curpath>", "r", , "<crlf>");

    foreach($file, $excludedFiles) {
        $matches = regexmatches($files, "^.*?" . $file . "$", "<crlf>");
        if ($matches) {
            foreach($match, $matches, "<crlf>") {
                $folder = regexmatches($match, "^.*(?=\\)");
                $folders = regexreplace($folders, replace($folder, "\", "\\") . ".*");
            }
        }
    }
    $folders = formatlist($folders, "dents", "<crlf>");
    text $folders;
It removes all folders (incl. subfolders) that contain any of the files in the $excludedFiles variable...

I like regexes, therefore this variant *g*

Wasn't that fun? No? :cry:
One of my scripts helped you out? Please donate via Paypal

Jeff Bellune
Posts: 284
Joined: 13 Dec 2007 12:55

Re: Command Number for "Copy Containing Folder(s)"?

Post by Jeff Bellune »

^^^^

Wow. Just wow.

Your approach is completely different than mine. Is it correct that you wrote a general script that can be used no matter what folders are part of the search and no matter what file(s) may be used as exclusion criteria? I'm just trying to write a simple script that will perform a one-time task (at least until ITunes Match trashes my iTunes Music folder structure again!).

I fear it will take me more time to parse and understand your method that it will for me to write my simple script. But yours should ultimately be way more useful! :)

I think it's time to visit your PayPal link...

Cheers,
Jeff

Jeff Bellune
Posts: 284
Joined: 13 Dec 2007 12:55

Re: Command Number for "Copy Containing Folder(s)"?

Post by Jeff Bellune »

@SammaySarkar:

May I donate to your favorite charity as well? (Where to send, please.)

Cheers,
Jeff

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

Re: Command Number for "Copy Containing Folder(s)"?

Post by highend »

Is it correct that you wrote a general script that can be used no matter what folders are part of the search and no matter what file(s) may be used as exclusion criteria?
Yes, it should work for both cases.
I fear it will take me more time to parse and understand your method
It isn't that complicated:
1. Define files to look for (their folders will be excluded later on
2. folderreport for all folders (recursively) which will be the masterlist for all folders to be excluded
3. folderreport for files so that we can match the excluded files with
4. foreach() loop to parse the excluded files
5. $matches contains all regexmatches for an excluded file
6. if... if we have a match, go on
7. another foreach loop that...
8. extract only the folder part from the file match
9. remove this folder from the masterlist
10. format the list of the rest of the masterlist (mainly to remove all those empty lines that the replace caused)

Show us your version if you like...
One of my scripts helped you out? Please donate via Paypal

Jeff Bellune
Posts: 284
Joined: 13 Dec 2007 12:55

Create a Search for folders without a certain file

Post by Jeff Bellune »

'It isn't that complicated"

You have a gift for understatement, sir. I'll post my effort as soon as I eliminate some stupid logic mistakes.

My current goal is to find all the folders in my iTunes Music folder that do not contain album art in the form of folder.jpg, except in the cases where folder.jpg has the system attribute. Once I find those folders, I can create a paper folder that contains all the files in those folders, then make an .m3u playlist out of all of them and open them in Mp3tag. Once in Mp3tag I can add album art to all the music tracks that need them.

The brute force way is to add all 15,000+ songs in all of the folders to the playlist, then filter them in Mp3tag. It takes forever to manipulate that many songs in Mp3tag, so I wanted to pare down the list as much as possible in XYplorer. Hence the script effort.

Cheers,
Jeff
Last edited by Jeff Bellune on 26 Aug 2014 19:12, edited 2 times in total.

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

Re: Command Number for "Copy Containing Folder(s)"?

Post by highend »

Code: Select all

    $iTunesFolder = "<curpath>";
    $folders = folderreport("dirs", "r", $iTunesFolder, "r", , "<crlf>");
    $files = folderreport("files", "r", $iTunesFolder, "r", , "<crlf>");

    $matches = regexmatches($files, "^.*?folder\.jpg$", "<crlf>");
    if ($matches) {
        foreach($match, $matches, "<crlf>") {
            $attribute = attrstamp(, 0, $match);
            if ("|4|5|6|7|36|37|38|39|" LikeI "*|$attribute|*") { // Ignore folder.jpg with system attribute
                $folder = regexmatches($match, "^.*(?=\\)");
                $folders = regexreplace($folders, replace($folder, "\", "\\") . ".*(\r?\n|$)");
            }
        }
    }
    paperfolder("iTunes", formatlist($folders, "dents", "<crlf>"), "<crlf>");
This should do what you want (up to the step: create a paperfolder of all folders).

Folders with folder.jpg files, which have the system attributes are excluded...
$iTunesFolder = ... should be set to the folder on your system.
One of my scripts helped you out? Please donate via Paypal

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Command Number for "Copy Containing Folder(s)"?

Post by bdeshi »

Code: Select all

            $attribute = attrstamp(, 0, $match);
            if ("|4|5|6|7|36|37|38|39|" LikeI "*|$attribute|*") { // Ignore folder.jpg with system attribute
I suggest ^ those ^ two lines be replaced with v these v :

Code: Select all

            $attribute = report("{attr}", $match);
            if (strpos($attribute, "S") != -1){ //Ignore folder.jpg with system attribute
Reason: The LikeI condition doesn't take into account a handful of extra attributes files can have. (compressed (C), indexed (I), Encrypted, ... )
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

Jeff Bellune
Posts: 284
Joined: 13 Dec 2007 12:55

Create a Search for folders without a certain file

Post by Jeff Bellune »

Thanks, guys. I have a lot to digest. I'll get back to you once I have time to analyze and test the code. I'd like to understand the syntax and logic enough to begin to do these kinds of simple things on my own.

Cheers,
Jeff
Last edited by Jeff Bellune on 26 Aug 2014 19:12, edited 1 time in total.

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

Re: Command Number for "Copy Containing Folder(s)"?

Post by highend »

A slightly different variation:

Code: Select all

    $iTunesFolder = "<curpath>";
    $folders = folderreport("dirs", "r", $iTunesFolder, "r", , "<crlf>");
    $files = folderreport("files", "r", $iTunesFolder, "r", , "<crlf>");

    $matches = regexmatches($files, "^.*?folder\.jpg$", "<crlf>");
    if ($matches) {
        $foldersToExclude = "";
        foreach($match, $matches, "<crlf>") {
            if (strpos(report("{attr}", $match), "s") != -1){ // Ignore folder.jpg with system attribute
                $foldersToExclude = $foldersToExclude . getpathcomponent($match, "path") . "|";
            }
        }
    }
    $folders = regexreplace(replacelist($folders, $foldersToExclude, "", "|"), "^\\.*?$");
    paperfolder("iTunes", formatlist($folders, "dents", "<crlf>"), "<crlf>");
The differences:
- Replaced one regex with getpathcomponent
- The foreach loop only builds a list of folders to exclude instead of using a regex to replace folders instantly
- At the end all folder parts are deleted via a simple replacelist() and only one call to a regexreplace() that deletes all folder part remainings (all parts that begin with a "\" (caused by the replacelist() command)

The result should be the same but on huge lists the new version should be considerable faster.
One of my scripts helped you out? Please donate via Paypal

Jeff Bellune
Posts: 284
Joined: 13 Dec 2007 12:55

Create a Search for folders without a certain file

Post by Jeff Bellune »

$excludedFiles = "AddonCopy.xys|COMMIT_EDITMSG";
I take it that this only works if git is installed? It's taken me a bit of searching on Google to come to that conclusion. I'm still not sure what that line of code is supposed to do, but I think it has something to do with the default git text editor being used to create or read the AddonCopy.xys file?

I guess the AddonCopy.xys file is supposed to contain the user's list of files to be to be used as criteria for removing folders?

So much time spent on one variant, so many more variants to go! And new scripts to parse arriving frequently! :D

I'm going to need more coffee...

Jeff

EDIT: I edited the subject of this post and a few before it to more accurately reflect how the subject has changed.
Last edited by Jeff Bellune on 26 Aug 2014 19:14, edited 1 time in total.

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

Re: Command Number for "Copy Containing Folder(s)"?

Post by highend »

No...
$excludedFiles = "AddonCopy.xys|COMMIT_EDITMSG";
This was just for testing purposes. The initial script should exclude folders with specific files in it. These were the two that I used. I didn't know in the first place which files you wanted to exclude. That's all. No deeper sense behind these two files.
One of my scripts helped you out? Please donate via Paypal

Jeff Bellune
Posts: 284
Joined: 13 Dec 2007 12:55

Create a Search for folders without a certain file

Post by Jeff Bellune »

I may be getting hung up on minutiae here.
$matches = regexmatches($files, "^.*?folder\.jpg$", "<crlf>");
Why the question mark before "folder"? I interpret it as limiting "anything from the beginning of the string" to 0 or 1 occurrences (lazy). But the script variables at this point in the script contain the exact same thing if I eliminate the question mark:

Code: Select all

$matches = regexmatches($files, "^.*folder\.jpg$", "<crlf>");
So what's the difference?

Thanks,
Jeff

Post Reply