Moving all files in a search result to new folder

If I want to move all files matching a tag from one folder to another, what’s the easiest way to do that? Drag’n’drop from the search result doesn’t work.

3 Likes

Hello,

Question: Do your file names have spaces / tabs / or quotes ??

If not, what i usually do is the following:

  1. Type the search
  2. Copy Search results (the obsidian icon option)
  3. !IMP! choose show path option
  4. Copy the list into a text file for e.g. move.txt
  5. Run the following shell command: cat PATH/TO/move.txt | xargs -I % sh -c 'echo \"PATH/TO/YOUR/VAULT/%\";' | xargs -I % sh -c 'cp -rf % PATH/TO/DESTINATION/FOLDER/'

P.S:

  • if your names have spaces and other path breaking characters you need to search / replace all of them to escape them before running the command otherwise the paths will be broken.
  • The path has to be either the absolute path or the relative path from where you are running the command. You need to replace PATH/TO/ and PATH/TO/YOUR/VAULT/ and PATH/TO/DESTINATION/FOLDER/ from the above command (keep everything else)
  • I am sorry if this is not what you are looking for

Edit 1:

This is from inside the note

To see where you are run the print working directory command below


Edit 2:
You can do the same thing using python instead of sh and **it wouldn't care about spaces / characters.**
I can share it if it is what you want please let me know.

3 Likes

Thanks. With 1600 files this process would probably take a lot of time. But for some reason, it made me realize that I could just use Finder to search for the relevant tags and make the move there. So, thanks! :slight_smile:

5 Likes

Hello, I’d be interested if you could share how I can do that using python. I want to move a lot of notes and all of them have spaces in their titles…

+1 We need the option to select multiple files and move them to a specific folder. Or a command to move multiple files.

1 Like

I’d also like this. My use case is being able to move a bunch of notes fro wherever they are to one place. This happens at the moment when I realize that they should be organized together, which is often well after they’ve been written.

2 Likes

Just use folders instead of trying to do technical feats with scripting… folders are not so bad. Use them to group related notes.
You’ll not lose flexibility of links, MOCs and tags… they are not mutually exclusive with folders after all.

If anyone is still interested in this, there is a great community plugin called ‘Auto Note Mover’.
It allows you to define rules for automatically moving notes into specific folders based on tags or phrases in the note title. Also supports regex.

Usually it is only triggered upon creating, editing or renaming a note.
For the purpose of moving all notes in the vault that fit a specific rule at once, there is a workaround:

  1. Create a new folder in the root of the vault
  2. Move all files and folders in the vault to the folder created in step 1 (except .obsidian, .git, etc.)
  3. Move the notes and folders moved in step 2 back to their original location.

This will trigger the plugin and all notes that fit a rule will be moved to the correct folder.
The workaround was proposed by the plugin developer in this GitHub issue thread.

The great thing is after the initial move you can leave the plugin turned on and it will automatically move all notes into the correct folders upon creation, so you will not have to worry about moving notes ever again!

5 Likes

Thanks for the cue :slight_smile:

I had to mess around a bit to make it work:

1 Like