Search code examples
pythonlinuxbashpython-2to3

bash equivalent for os.walk?


I am using 2to3 to fix my script library, and it seems to be a command line thing, not a shell thing.

I want to do all files from /home/me/scripts downward, assuming they end in .py. Is there an easy way to do 2to3 -y filename for each file under my folder in the shell?


Solution

  • There's find command:

     find /home/me/scripts  -iname "*.py" -exec 2to3 {} \;
    

    The -exec argument tell it to execute the command that follows after this argument, which is 2to3 {} in this case. For each file found, {} is replaced by the name of that file.