/* =============================================================================== Source : https://resource.dopus.com/t/quick-buttons-for-directory-organisation/6532/27 Function : Move Here to New Subfolder Created : 2022-08-16 Modified : 2023-09-16 Version : v1.6.1 =============================================================================== */ //-- Add string trim() method String.prototype.trim = function(s){s=s||"\\s";return this.replace(new RegExp("^("+s+"){1,}\|("+s+"){1,}$","g"),"");} function OnClick(clickData) { var cmd = clickData.func.command; var tab = clickData.func.sourcetab; var sourcepath = tab.path; var selectedItems = tab.selected; if (selectedItems.count == 0) { cmd.RunCommand('CreateFolder READAUTO=no'); } else { //var focusI = tab.GetFocusItem.name_stem; //Get the base name of the item in focus var dlg = clickData.func.Dlg(); dlg.title = "Directory Opus"; // Title dlg.template = "dlgCombox"; dlg.detach = true; dlg.Create(); dlg.Control("static").style = "b"; dlg.Control("static").label = "Move Here to New Subfolder"; // Topic dlg.Control("static2").label = "Select or enter folder name or subpath"; // Notes dlg.Control("static3").label = "D:\\Icons\\MOVE.png"; // Icon dlg.Control("combo").label = tab.selected(0).name_stem; // Defalut value dlg.Control("combo").SelectRange(0, -1); // Select defalut value for(var e = new Enumerator(selectedItems); !e.atEnd(); e.moveNext()) { dlg.Control("combo").AddItem(e.item().name_stem_m); //Add each item to drop-down list } dlg.Show(); // msg loop do { msg = dlg.GetMsg(); /* // Selection if(msg == true && dlg.Control("combo").focus == true) { DOpus.Output(dlg.Control("combo").label); } */ // Result, perform the move operation if (dlg.result == 1) { var newSubfolder = dlg.Control("combo").label.trim(); if (newSubfolder == "") return newPath = sourcepath + "\\" + newSubfolder; if (DOpus.FSUtil.Exists(newPath)) { cmd.ClearFiles(); for(var e = new Enumerator(selectedItems); !e.atEnd(); e.moveNext()) { // If the folder exists, do not move the folder itself eItem = e.item() + ""; if (eItem != newPath) cmd.AddFile(eItem) } } cmd.RunCommand('Copy MOVE HERE CREATEFOLDER="' + newSubfolder + '"'); // Create a folder and move the selected items into it } /* // If the button 3 is pressed if(dlg.result == 2) { DOpus.Output("Button 3 is pressed"); } // If the button 4 is pressed if(dlg.result == 3) { DOpus.Output("Button 4 is pressed"); } */ } while (msg == true); } } ==SCRIPT RESOURCES