Advertisement
Guest User

dopus_moveUp

a guest
May 27th, 2015
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @script jscript
  2. ///////////////////////////////////////////////////////////////////////////////
  3. function OnClick(data) {
  4.     DOpus.ClearOutput();
  5.     data.func.command.ClearFiles();
  6.     //get enumerator and count of selected folders or complete list of folders
  7.     var folders = GetFolders(data);
  8.     while (!folders.enumerator.atEnd()) {
  9.       var folder = folders.enumerator.item();
  10.       folders.enumerator.moveNext();
  11.       dout("Folder [" + folder.name + "]..");
  12.       MoveSingleFilesUp(folder.path, folder.name);
  13.     }
  14.   }
  15.   ///////////////////////////////////////////////////////////////////////////////
  16. function ReadFolder(path, recurse, exception) {
  17.     if (recurse == undefined) recurse = false;
  18.     if (exception == undefined) exception = true;
  19.     var fEnum = DOpus.FSUtil.ReadDir(path, true);
  20.     if (fEnum.error != 0) {
  21.       var error = "ReadFolder(): Error reading folder [" + path + "], code [" + fEnum.error + "].";
  22.       if (exception) throw error;
  23.       dout(error);
  24.     }
  25.     return fEnum;
  26.   }
  27.   ///////////////////////////////////////////////////////////////////////////////
  28. function MoveSingleFilesUp(path, name) {
  29.     folderPath = path + "\\" + name
  30.     var fEnum = ReadFolder(folderPath, true, false);
  31.     while (!fEnum.complete && (fItem = fEnum.Next())) {
  32.       if (fItem.is_dir) {
  33.         MoveSingleFilesUp(fItem.path, fItem.name);
  34.       } else {
  35.         if (name == 'jpg' || name == 'tiff') {
  36.           var parentFolder = GetPathLastFolder(new String(folderPath)).parentPath;
  37.           if (parentFolder != "") {
  38.             dout("Moving up: " + fItem.name + " from [" + folderPath + "] to [" + parentFolder + "]");
  39.             var cmd = 'COPY MOVE FILE "' + folderPath + '\\' + fItem.Name + '" TO "' + parentFolder + '"';
  40.             DOpus.NewCommand.RunCommand(cmd);
  41.           }
  42.         }
  43.       }
  44.     }
  45.     if (name == 'jpg' || name == 'tiff') {
  46.       dout("Delete folder: " + folderPath);
  47.       var cmd = 'DELETE QUIET "' + folderPath + '"';
  48.       DOpus.NewCommand.RunCommand(cmd);
  49.     }
  50.   }
  51.   ///////////////////////////////////////////////////////////////////////////////
  52. function GetFolders(data) {
  53.     if (data.func.sourcetab.selected_dirs.count)
  54.       var dirs = data.func.sourcetab.selected_dirs;
  55.     else
  56.       var dirs = data.func.sourcetab.dirs;
  57.     return {
  58.       enumerator: new Enumerator(dirs),
  59.       count: dirs.count
  60.     };
  61.   }
  62.   ///////////////////////////////////////////////////////////////////////////////
  63. function GetPathLastFolder(mypath) {
  64.     mypath = mypath.replace(/(^(\s|\/|\\)+)|((\s|\/|\\)+$)/g, "");
  65.     var lastIndex = mypath.lastIndexOf('\\');
  66.     if (lastIndex == -1 || (lastIndex + 1) == mypath.length) return {
  67.       folder: mypath,
  68.       parentPath: ""
  69.     };
  70.     return {
  71.       folder: mypath.substring(lastIndex + 1),
  72.       parentPath: mypath.substring(0, lastIndex)
  73.     };
  74.   }
  75.   ///////////////////////////////////////////////////////////////////////////////
  76. function dout(text) {
  77.   DOpus.Output(text);
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement