Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @script jscript
- ///////////////////////////////////////////////////////////////////////////////
- function OnClick(data) {
- DOpus.ClearOutput();
- data.func.command.ClearFiles();
- //get enumerator and count of selected folders or complete list of folders
- var folders = GetFolders(data);
- while (!folders.enumerator.atEnd()) {
- var folder = folders.enumerator.item();
- folders.enumerator.moveNext();
- dout("Folder [" + folder.name + "]..");
- MoveSingleFilesUp(folder.path, folder.name);
- }
- }
- ///////////////////////////////////////////////////////////////////////////////
- function ReadFolder(path, recurse, exception) {
- if (recurse == undefined) recurse = false;
- if (exception == undefined) exception = true;
- var fEnum = DOpus.FSUtil.ReadDir(path, true);
- if (fEnum.error != 0) {
- var error = "ReadFolder(): Error reading folder [" + path + "], code [" + fEnum.error + "].";
- if (exception) throw error;
- dout(error);
- }
- return fEnum;
- }
- ///////////////////////////////////////////////////////////////////////////////
- function MoveSingleFilesUp(path, name) {
- folderPath = path + "\\" + name
- var fEnum = ReadFolder(folderPath, true, false);
- while (!fEnum.complete && (fItem = fEnum.Next())) {
- if (fItem.is_dir) {
- MoveSingleFilesUp(fItem.path, fItem.name);
- } else {
- if (name == 'jpg' || name == 'tiff') {
- var parentFolder = GetPathLastFolder(new String(folderPath)).parentPath;
- if (parentFolder != "") {
- dout("Moving up: " + fItem.name + " from [" + folderPath + "] to [" + parentFolder + "]");
- var cmd = 'COPY MOVE FILE "' + folderPath + '\\' + fItem.Name + '" TO "' + parentFolder + '"';
- DOpus.NewCommand.RunCommand(cmd);
- }
- }
- }
- }
- if (name == 'jpg' || name == 'tiff') {
- dout("Delete folder: " + folderPath);
- var cmd = 'DELETE QUIET "' + folderPath + '"';
- DOpus.NewCommand.RunCommand(cmd);
- }
- }
- ///////////////////////////////////////////////////////////////////////////////
- function GetFolders(data) {
- if (data.func.sourcetab.selected_dirs.count)
- var dirs = data.func.sourcetab.selected_dirs;
- else
- var dirs = data.func.sourcetab.dirs;
- return {
- enumerator: new Enumerator(dirs),
- count: dirs.count
- };
- }
- ///////////////////////////////////////////////////////////////////////////////
- function GetPathLastFolder(mypath) {
- mypath = mypath.replace(/(^(\s|\/|\\)+)|((\s|\/|\\)+$)/g, "");
- var lastIndex = mypath.lastIndexOf('\\');
- if (lastIndex == -1 || (lastIndex + 1) == mypath.length) return {
- folder: mypath,
- parentPath: ""
- };
- return {
- folder: mypath.substring(lastIndex + 1),
- parentPath: mypath.substring(0, lastIndex)
- };
- }
- ///////////////////////////////////////////////////////////////////////////////
- function dout(text) {
- DOpus.Output(text);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement