2

I want to run a command from root folder recursively which will affect all files under that root folder with a specific extension.

Here is the command

blender b03.blend --background --python myScript.py 

Instead of b03.blend file I want to run this command for every file with .blend extension.

1
  • I suggest to take a look at GNU find and its action -exec command ;. Commented May 20, 2017 at 16:09

1 Answer 1

5

Try:

find . -name '*.blend' -exec blender {} --background --python myScript.py \; 

Explanation:

  • find any file that matches *.blend - use of single quotes is important so that your shell doesn't expand this for any files in the current directory
  • then for each file found, execute blender {} --background --python myScript.py. The {} is replaced with the file's name, for example some/sub/tree/file.blend.
  • \; will terminate the -exec statement. The \ is used to escape the ;, so that the shell doesn't absorb it and split the line into multiple commands.
  • All instances of blender will be run from the initial working directory, so blender must be able to correctly handle a file that is not 'here', and equally access the myScript.py that is not a neighbour of the *.blend file(s).

NOTE: I'm not familiar with blend, but if it will go into the background and take some time to process (due to --background), then you may overwhelm your machine... You might prefer to process one file at a time, or perhaps break the job into a handful of independent jobs that can run serially (each item to completion)... for bonus points look at something like make that can easily run concurrent operations while working with restrictions (e.g: make -j 8 will run at most 8 commands at once).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.