How to Move all Word Documents from a Folder & Subfolders?

I have a folder with numerous sub folders and sub-sub folders. Within those sub folders and sub-sub folders are various PDFs and Microsoft Word documents.

I’d like to find a way to pull out all of the Microsoft Word documents and move them to a separate, single folder.

I’ve played with both Hazel and Automator for a while trying to figure out how to make this work, and am hitting a wall. I’m certain it’s possible (doesn’t seem too complicated)… any ideas?

Open a Finder window, navigate to the root folder (the top-most folder that contains the sub- and sub-sub- folders) and type .docx into the search bar in the top right of the Finder window and it will show all of the .docx files contained in the folder and all of its sub-folders, all of their sub-folders, etc.

If you have to find .docx and .doc files, you can either do this twice or “level up” and click into the search bar in the top right of the Finder window, hit the space bar, and then click the plus sign that pops up below that search bar which gives you a “smart search” (like a Smart Folder) that you can do a lot with.

The default is to search by Name but to achieve what you want to you have to hold the Option key down and then click the “…” on the right side of the finder window which opens an “Any of the following are true” search parameter that should look like this:

From there, click the plus sign to the right of the first search parameter that is inside the “Any” parameter so that there are two, and then set their initial parameters to “File extension”, which may or may not be in the short dropdown list. If they aren’t, click “Other…” at the bottom and find them in the window that pops up there, then set the extensions to .doc and .docx

Now you will have something that looks like this:

Which should show you exactly what you want!

If you’re comfortable with the terminal,

# within the top level directory
find . -name '*.docx' -exec mv {} <new location>
# The above line explained:
# - 'find' : the name of the command
# - '.' : the location to search in recursively
# -  '-name '*.docx'': the name of the file has a docx extension
# - '-exec': run the following command for each result
# - 'mv {} <new location>': mv the current path result to the passed in new location 
# Where '<new location>' is a the directory you want to move them all to
3 Likes

Thank you both! Really appreciate it.

2 Likes

When scripting mv on macOS, you should always always always always always be using mv -n not just mv.

The -n will prevent mv from overwriting a file with the same name.

For example, imagine you had a file named “Contract.docx” in ~/Documents/ClientA/ and another file called “Contract.docx” in ~/Documents/ClientB/.

Now imagine that you can the originally suggested mv command…end result?

You only have one “Contract.docx” file now. Which would be bad.

If you used mv -n then the second one would have stayed in the original folder. So you would have to go back and find it, but at least it would be there.

Also, when you run find and have an -exec command, you need to end it with \;so the command should be like this:

find . -name '*.docx' -exec mv -n {} <new location> \;
3 Likes

Thanks for this clarification, I’d never heard of the -n argument.

Also, when you run find and have an -exec command, you need to end it with ;so the command should be like this:

:sweat: I always mix up the argument styling between find and fd

In zsh (default since Catalina):

mv -n **/*.docx ~/Documents/Destination/Whatever