function OnInit(initData) { initData.name = 'WslFind'; initData.version = '2023-11-15'; initData.copyright = ''; initData.url = 'https://resource.dopus.com/t/wslfind-find-files-with-linux/46976'; initData.desc = 'Find files with WSL find command. More info: wsl find -help'; initData.default_enable = true; initData.min_version = '12.0'; } function OnAddCommands(addCmdData) { var cmd = addCmdData.AddCommand(); cmd.name = 'WslFind'; cmd.method = 'OnWslFind'; cmd.desc = ''; cmd.label = ''; cmd.template = 'expression,path/k/m'; cmd.hide = false; cmd.icon = 'script'; } function OnWslFind(scriptCmdData) { var cmd = scriptCmdData.func.command; var args = scriptCmdData.func.args; var tab = scriptCmdData.func.sourcetab; var fsu = DOpus.FSUtil(); var stt = DOpus.Create().StringTools(); cmd.deselect = false; if (args.got_arg.path) { var itemsToEnum = args.path; } else { var itemsToEnum = tab.selected_dirs.count > 0 ? tab.selected_dirs : DOpus.Create().Vector(tab.path); } var strPath = ''; for (var e = new Enumerator(itemsToEnum); !e.atEnd(); e.moveNext()) { var wslPath = GetWslPath(fsu.Resolve(e.item())); if (!wslPath) continue; if (strPath) strPath += ' '; strPath += '"' + wslPath + '"'; } if (!strPath) { DOpus.Output('Path missing or invalid.'); return; } var strExpression = args.expression; var exportFile = fsu.GetTempFilePath(); cmd.Clear(); cmd.SetType('msdos'); cmd.SetModifier('runmode', 'hide'); var cmdLine = 'wsl find' + ' ' + strPath + ' ' + strExpression + ' > "' + exportFile + '"'; DOpus.Output(cmdLine); cmd.RunCommand(cmdLine); var fileList = stt.Decode(fsu.GetItem(exportFile).Open().Read(), 'utf8').replace(/(^|\n)\/mnt\/(\w)/g, '$1$2:'); var importFile = fsu.GetTempFile(); if (fileList != '') importFile.Write(fileList); importFile.Close(); var newColl = 'coll://WSL-' + DOpus.Create().Date().Format('D#yyyyMMdd-T#HHmmss'); cmd.RunCommand('CreateFolder NAME="' + newColl + '"'); cmd.RunCommand('SetAttr' + ' FILE="' + newColl + '"' + ' DESCRIPTION="' + strExpression.replace(/"/g, '""') + '"'); cmd.ClearFiles(); cmd.AddFilesFromFile(importFile, 'utf8'); cmd.SetDest(newColl); cmd.RunCommand('Copy COPYTOCOLL=member'); cmd.RunCommand('Go' + ' PATH="' + newColl + '"' + ' OPENINDUAL' + ' TOFRONT'); } function GetWslPath(item) { var tmp = String(item); if (tmp.charAt(1) == ':') { return '/mnt/' + tmp.charAt(0).toLowerCase() + tmp.substring(2).replace(/\\/g, '/'); } else { return ''; } } // Set COLUMNSTOGGLE="desc(!,a,0)" // Set COLUMNSTOGGLE="userdesc(!,a,0)"