No internet connection
  1. Home
  2. How to

Finder - move selected files to "_OLD" folder

By Vanessa Garde @Vanessa_Garde
    2021-02-01 07:48:35.408Z

    Hi there,

    I'd love to be able to have a shortcut in finder to:

    • Move selected files to an "_OLD" folder, if existing on the same location.
    • If not, create an "_OLD" folder (without the quotes) and them move the selected files to that location.

    Any hints, please? :-)

    Thanks a lot!!!

    Vanessa G.

    Solved in post #2, click to view
    • 3 replies
    1. This should do it :)

      
      function moveFiles({ sourcePaths, targetFolder }) {
      
          for(let sourcePath of sourcePaths) {
              var sourceFilename = sourcePath.split('/').slice(-1)[0];
              var targetPath = targetFolder + '/' + sourceFilename;
      
              sf.file.move({
                  sourcePath: sourcePath,
                  destinationPath: targetPath,
              });
          }
      
      }
      
      function main() {
      
          var sourcePaths = Array.from(sf.ui.finder.selectedPaths);
          if (sourcePaths.length === 0) return;
      
          var sourceFolder = sourcePaths[0].split('/').slice(0, -1).join('/');
          var targetFolder = `${sourceFolder}/_OLD`;
      
          sf.file.directoryCreate({ path: targetFolder });
      
          moveFiles({
              sourcePaths,
              targetFolder,
          });
      }
      
      main();
      
      Reply3 LikesSolution
      1. VVanessa Garde @Vanessa_Garde
          2021-02-01 15:09:26.955Z

          Wow! That worked!!! Thank you so much!!!! :-)

          1. In reply tochrscheuer:
            RRob Byers @Rob_Byers
              2022-01-22 23:42:16.337Z

              This is a part of my workflow as well, and just came on the forum on a whim to see if I could use SoundFlow to automate it. First result brings me to this question and code. THANK YOU both! Putting it to work immediately!