Advertisement
Guest User

dopus_moveUp_noLog

a guest
May 28th, 2015
335
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.     dout("Finish!");
  15.   }
  16.   ///////////////////////////////////////////////////////////////////////////////
  17. function ReadFolder(path, recurse, exception) {
  18.     if (recurse == undefined) recurse = false;
  19.     if (exception == undefined) exception = true;
  20.     var fEnum = DOpus.FSUtil.ReadDir(path, true);
  21.     if (fEnum.error != 0) {
  22.       var error = "ReadFolder(): Error reading folder [" + path + "], code [" + fEnum.error + "].";
  23.       if (exception) throw error;
  24.       //dout(error);
  25.     }
  26.     return fEnum;
  27.   }
  28.   ///////////////////////////////////////////////////////////////////////////////
  29. function MoveSingleFilesUp(path, name) {
  30.     folderPath = path + "\\" + name
  31.     var fEnum = ReadFolder(folderPath, true, false);
  32.     while (!fEnum.complete && (fItem = fEnum.Next())) {
  33.       if (fItem.is_dir) {
  34.         MoveSingleFilesUp(fItem.path, fItem.name);
  35.       } else {
  36.         if (name == 'jpg' || name == 'tiff') {
  37.           var parentFolder = GetPathLastFolder(new String(folderPath)).parentPath;
  38.           if (parentFolder != "") {
  39.             //dout("Moving up: " + fItem.name + " from [" + folderPath + "] to [" + parentFolder + "]");
  40.             var cmd = 'COPY MOVE FILE "' + folderPath + '\\' + fItem.Name + '" TO "' + parentFolder + '"';
  41.             DOpus.NewCommand.RunCommand(cmd);
  42.           }
  43.         }
  44.       }
  45.     }
  46.     if (name == 'jpg' || name == 'tiff') {
  47.       //dout("Delete folder: " + folderPath);
  48.       var cmd = 'DELETE QUIET "' + folderPath + '"';
  49.       DOpus.NewCommand.RunCommand(cmd);
  50.     }
  51.   }
  52.   ///////////////////////////////////////////////////////////////////////////////
  53. function GetFolders(data) {
  54.     if (data.func.sourcetab.selected_dirs.count)
  55.       var dirs = data.func.sourcetab.selected_dirs;
  56.     else
  57.       var dirs = data.func.sourcetab.dirs;
  58.     return {
  59.       enumerator: new Enumerator(dirs),
  60.       count: dirs.count
  61.     };
  62.   }
  63.   ///////////////////////////////////////////////////////////////////////////////
  64. function GetPathLastFolder(mypath) {
  65.     mypath = mypath.replace(/(^(\s|\/|\\)+)|((\s|\/|\\)+$)/g, "");
  66.     var lastIndex = mypath.lastIndexOf('\\');
  67.     if (lastIndex == -1 || (lastIndex + 1) == mypath.length) return {
  68.       folder: mypath,
  69.       parentPath: ""
  70.     };
  71.     return {
  72.       folder: mypath.substring(lastIndex + 1),
  73.       parentPath: mypath.substring(0, lastIndex)
  74.     };
  75.   }
  76.   ///////////////////////////////////////////////////////////////////////////////
  77. function dout(text) {
  78.   DOpus.Output(text);
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement