Script from Hell?

Blender artists, this script is supposed to copy fbx files from a subfolder A to another folder B, but it is doing the opposite. It is copying all the files instead of just fbx files. Here is the code, I need help please

import bpy
import os
import shutil
import glob, sys

dir1=Folder A
dir2=Folder B

for root, dirs, files in os.walk(dir1):
    for file in files:
        if (file.endswith(".fbx")):
            print(os.path.join(root,file))
        shutil.copy2(os.path.join(root,file), dir2)

First your last line, is not well indented. Meaning it’ll copy everything (as you said), but just print the filename if .FBX is encountered.

Dunno if uppercase and lowercase are treated correctly on “endswith” (look at the doc :wink:

Additionnaly, you declare dir1, dir2, but you used dir2 and dir3, that’s strange

1 Like

the dir1 nd dir 2 are just placeholders, I actually mean the same thing. I tried changing FBX to fbx, same error happens.

Yes but the indentation of shutil.copy2 line make it out of the “IF file ends with fbx” scope. That’s the issue.

OMG, it was this little thing that :man_facepalming:

Thank you. It works!