New -So thought I would ask an expert - file select and copy script

I've not had time to get into scripting and have a project I need to organize quickly and do a simple move of all the files in a selected directory up 1 level.

So, the script idea (or whatever else can do this in opus).

I select a folder and run the script while that folder is selected.

The script does the following:

(1) Selects all the files in the selected directory
(2) Moves all the selected files up into the parent directory.

So, in this example all the mp3 files in the "fly me to the moon" directory move up to the "Frank Sinatra" directory.

Thanks for the help...best regards.

Thanks... was a c# programmer before I retired so I guess I'll jump into some documentation for syntax learning to really use the power in this program. Loving it so far. If or when time permits. Who knew retirement would make a person so busy.

@confirm Move all the files and folders in the current directory up one level and then delete the current folder?
@set ChildPath={sourcepath$|noterm}
Copy MOVE * TO ..
Go ..
Delete FILE="{$ChildPath}" NORECYCLE SKIPNOTEMPTY QUIET

This moves everything up and deletes the folder. There is confirmation dialog. You can always omit the Delete line if you want to keep the empty folder

Hey thanks.. was having issues with it copying to C:\ not the parent directory in this example C:\test1

C:\test1\test2 (files being in here)

So made another one:

function OnClick(clickData) {
    var tab = clickData.func.sourcetab;
    var selectedItems = tab.selected;

    if (selectedItems.count !== 1 || !selectedItems(0).is_dir) {
        DOpus.Output("Please select exactly one folder.");
        return;
    }

    var selectedFolderItem = selectedItems(0);
    var selectedFolderPath = String(selectedFolderItem.realpath);

    var lastSlash = selectedFolderPath.lastIndexOf("\\");
    if (lastSlash < 3) {
        DOpus.Output("Unable to determine parent path from: " + selectedFolderPath);
        return;
    }

    var parentPath = selectedFolderPath.substring(0, lastSlash);

    var fsu = DOpus.FSUtil();
    var folderEnum = fsu.ReadDir(selectedFolderPath);
    var fileCount = 0;
    var fileList = "";

    while (!folderEnum.complete) {
        var item = folderEnum.Next();
        if (!item.is_dir) {
            fileList += '"' + selectedFolderPath + "\\" + item.name + '" ';
            fileCount++;
        }
    }

    DOpus.Output("Preparing to move " + fileCount + " files from '" + selectedFolderPath + "' to '" + parentPath + "'.");

    if (fileCount > 0) {
        // Create an external command and run it
        var shellCommand = 'Copy MOVE FILE ' + fileList + 'TO="' + parentPath + '"';
        var cmd = clickData.func.command;
        cmd.ClearFiles();
        cmd.RunCommand(shellCommand);
    }
}

Script 2: Moves all the files and subfolders from the selected folder to the parent, then deletes the selected folder for good house cleaning.

function OnClick(clickData) {
    var tab = clickData.func.sourcetab;
    var selectedItems = tab.selected;

    if (selectedItems.count !== 1 || !selectedItems(0).is_dir) {
        DOpus.Output("Please select exactly one folder.");
        return;
    }

    var selectedFolderItem = selectedItems(0);
    var selectedFolderPath = String(selectedFolderItem.realpath);

    // Manually derive parent path
    var lastSlash = selectedFolderPath.lastIndexOf("\\");
    if (lastSlash < 3) {
        DOpus.Output("Unable to determine parent path from: " + selectedFolderPath);
        return;
    }

    var parentPath = selectedFolderPath.substring(0, lastSlash);

    // Prepare FSUtil and folder listing
    var fsu = DOpus.FSUtil();
    var folderEnum = fsu.ReadDir(selectedFolderPath);
    var cmd = clickData.func.command;

    var filesToMove = "";
    var foldersToMove = "";
    var fileCount = 0;
    var folderCount = 0;

    // Collect files and folders for moving
    while (!folderEnum.complete) {
        var item = folderEnum.Next();
        var itemPath = selectedFolderPath + "\\" + item.name;

        if (item.is_dir) {
            foldersToMove += '"' + itemPath + '" ';
            folderCount++;
        } else {
            filesToMove += '"' + itemPath + '" ';
            fileCount++;
        }
    }

    DOpus.Output("Moving " + fileCount + " files and " + folderCount + " folders from '" + selectedFolderPath + "' to '" + parentPath + "'.");

    // Move files
    if (filesToMove.length > 0) {
        cmd.RunCommand('Copy MOVE FILE ' + filesToMove + ' TO="' + parentPath + '"');
    }

    // Move folders
    if (foldersToMove.length > 0) {
        cmd.RunCommand('Copy MOVE FILE ' + foldersToMove + ' TO="' + parentPath + '"');
    }

    // Re-scan folder to check if it's now empty
    var contentsAfterMove = fsu.ReadDir(selectedFolderPath);
    var hasRemainingItems = false;

    while (!contentsAfterMove.complete) {
        var leftover = contentsAfterMove.Next();
        hasRemainingItems = true;
        break;
    }

    if (!hasRemainingItems) {
        cmd.RunCommand('Delete QUIET NORECYCLE FILE="' + selectedFolderPath + '"');
        DOpus.Output("Deleted empty folder: " + selectedFolderPath);
    } else {
        DOpus.Output("Folder '" + selectedFolderPath + "' still contains items. Not deleted.");
    }
}

My new modified UI (love this product):

Went back to the first one and cleaned it up:

Script 1: Copies files only to parent. If directory is empty it deletes it for good house keeping:

function OnClick(clickData) {
    var tab = clickData.func.sourcetab;
    var selectedItems = tab.selected;

    if (selectedItems.count !== 1 || !selectedItems(0).is_dir) {
        DOpus.Output("Please select exactly one folder.");
        return;
    }

    var selectedFolderItem = selectedItems(0);
    var selectedFolderPath = String(selectedFolderItem.realpath);

    var lastSlash = selectedFolderPath.lastIndexOf("\\");
    if (lastSlash < 3) {
        DOpus.Output("Unable to determine parent path from: " + selectedFolderPath);
        return;
    }

    var parentPath = selectedFolderPath.substring(0, lastSlash);
    var fsu = DOpus.FSUtil();
    var folderEnum = fsu.ReadDir(selectedFolderPath);
    var fileCount = 0;
    var fileList = "";

    while (!folderEnum.complete) {
        var item = folderEnum.Next();
        if (!item.is_dir) {
            fileList += '"' + selectedFolderPath + "\\" + item.name + '" ';
            fileCount++;
        }
    }

    DOpus.Output("Preparing to move " + fileCount + " files from '" + selectedFolderPath + "' to '" + parentPath + "'.");

    if (fileCount > 0) {
        var shellCommand = 'Copy MOVE FILE ' + fileList + 'TO="' + parentPath + '"';
        var cmd = clickData.func.command;
        cmd.ClearFiles();
        cmd.RunCommand(shellCommand);
    }

    // After move, re-check folder contents
    var refreshEnum = fsu.ReadDir(selectedFolderPath);
    var remainingFiles = 0;
    var remainingFolders = 0;

    while (!refreshEnum.complete) {
        var item = refreshEnum.Next();
        if (item.is_dir) remainingFolders++;
        else remainingFiles++;
    }

    if (remainingFiles === 0 && remainingFolders === 0) {
        var cleanupCmd = clickData.func.command;
        cleanupCmd.ClearFiles();
        cleanupCmd.AddFile(selectedFolderItem);
        cleanupCmd.RunCommand('Delete QUIET');
        DOpus.Output("✅ Folder '" + selectedFolderPath + "' was empty and has been deleted.");
    } else {
        DOpus.Output("⚠️ Folder '" + selectedFolderPath + "' still contains items, not deleted.");
    }
}