Copy/Move to Recent

Discuss and share scripts and script files...
Post Reply
LittleBiG
Posts: 1848
Joined: 08 Apr 2011 12:57
Location: Win10x64

Copy/Move to Recent

Post by LittleBiG »

I had an old request. Since CopyTo... and MoveTo... shell commands work only with Favorite Folders and Tabs, I wanted Recent locations also as a destination. http://www.xyplorer.com/xyfc/viewtopic.php?f=5&t=7620
In a previous beta we got get("list_recentlocations") command, so I was able to develop this missing feature. I think it can be interesting for other people, because it shows how a script can change itself during running. It can pretend for example a toggle button, which can change its state on clicking.

Preparations:
1. The script name have to be copy_recent.xys in the general Scripts folder.
2. Make a new user button, the On Click event should be: load "copy_recent", "_loadrec"; load "copy_recent" The first command creates the recent menu, the second shows the menu for us.

Usage:
If you click this new user button, the first row of the menu shows the operation type. If you click on that, the operation will change from Copy to Move and vica versa. If you click on a folder below, the files selected on the list panel will be copied or moved to that recent location, according to the operation in the first menu row.

Code: Select all

"_loadrec"
  $limit = 15;
  $sfile = readfile("<xydata>\Scripts\copy_recent.xys");
  // the sript remains the same before the separator
  $sfile = SubStr($sfile, 0, StrPos($sfile,'"-"', -1) + 3) . "<crlf>";
  $mostrecent = get("list_recentlocations");
  $i = 1;
  $ownrecent = "";
  // the limit contains the max number of the recent folders
  while ($i <= $limit) {
    // The first recent folder is the actual one. So have to start with the second folder.
    $path = gettoken ($mostrecent, $i+1, "<crlf>");
    if ($path != "") {
      // creating the command which will execute the copy or move command.
      $ownrecent = $ownrecent . '"' . $path . '|:copyto" if (get("CountSelected") > 0) { copyto "' . $path . '" } else { status "Nothing is selected!", , "alert" }';
      $ownrecent = $ownrecent . "<crlf>";
    }
    $i++;
  }
  // sorting the recent folders
  $ownrecent = formatlist($ownrecent,"se","<crlf>");
  // attach the recent folders to the end of the script, after the separator
  $sfile = $sfile . $ownrecent;
  // write the script back to the original script file
  writefile("<xydata>\Scripts\copy_recent.xys", $sfile, "o");
"Operation: COPY|:nuke"
  $sfile=readfile("<xydata>\Scripts\copy_recent.xys");
  if ( StrPos($sfile, "Operation: " . "COPY") == -1) {
    // change the operation label, it will seem as a toggle button
    $sfile=replace($sfile, "Operation: " . "MOVE", "Operation: " . "COPY", , , 1);
    // change the commands
    $sfile=replace($sfile, " mo" . "veto ", " co" . "pyto ");
    //change the icons of recent folders
    $sfile=replace($sfile, "|:c" . "ut", "|:co" . "pyto");
  }
  else {
    // change the operation label, it will seem as a toggle button
    $sfile=replace($sfile, "Operation: " . "COPY", "Operation: " . "MOVE", , , 1);
    // change the commands
    $sfile=replace($sfile, " co" . "pyto ", " mo" . "veto ");
    //change the icons of recent folders
    $sfile=replace($sfile, "|:co" . "pyto", "|:c" . "ut");
  }
  // write the script back to the original script file
  writefile("<xydata>\Scripts\copy_recent.xys", $sfile, "o");
"-"

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

Re: Copy/Move to Recent

Post by LittleBiG »

Sorting ability of the recent locations in the menu.

Modify _loadrec:

Code: Select all

// sorting the recent folders
  if (StrPos($sfile,"Sorting: " . "YES") != -1) {
    $ownrecent = formatlist($ownrecent,"se","<crlf>");
  }
Add this after "Operation:"

Code: Select all

"Sorting: NO|:sort"
  $sfile=readfile("<xydata>\Scripts\copy_recent.xys");
  if ( StrPos($sfile, "Sorting: " . "YES") == -1) {
    // change the sorting label
    $sfile=replace($sfile, "Sorting: " . "NO", "Sorting: " . "YES", , , 1);
  }
  else {
    // change the sorting label
    $sfile=replace($sfile, "Sorting: " . "YES", "Sorting: " . "NO", , , 1);
  }
  // write the script back to the original script file
  writefile("<xydata>\Scripts\copy_recent.xys", $sfile, "o");

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

Re: Copy/Move to Recent

Post by LittleBiG »

This is the last and most complete version of my Copy/Move to Recent script. File name doesn't matter anymore, because I used the self("file") command. The icons has been changed to the appropiate folder icons. I added a third option: type (RECENT/HOTLIST). RECENT type simply gets the first several items of the recent location. My personal best is the HOTLIST type.

It has 2 major differences from the original hotlist of XYplorer:
1. Mine doesn't remove the folders which don't exist. So my temporary unavailable folders remain.
2. Original hotlist removes all folder which are not leaves, assuming that the parent items are just transit stations. Completely wrong idea in my point of view. They are transit stations only if they are neigbours in the recent list! That shows, it was just a temporary path when I went down or up in the file system. But, for example, if "C:\Downloads" and "C:\Downloads\Softwares" are far from each other, that means "C:\Downloads" was not transit to the Software folder (probably I clicked it intentionally), so I want to see it in my hotlist as well. My HOTLIST type in the script is developed in accordance with this principle.

EDIT: I have just made a little but fancy change. If nothing is selected, all folder is disabled in the menu.
To see the attached files, you need to log into the forum.

Post Reply