• Helping you upgrade your CG career

    How to get file type or file extension from a list of files


    Howdy people :)

    ok I have a couple of maxscript questions - If I have a list of files in a folder acquired through maxscript, then how do I segregate them into different file extensions or file types ? I am using the maxscript command getFiles to get all files from a folder. I could supply getFiles with a parameter which would filter out a particular extension, but problem is that I want to filter out not one but 3 different file types. My code so far:

    my_files = getFiles "D:/Work/MaxProject/XXX/*.*"
    print my_files

    So, basically I need to filter 3 types of files from my_files - viz .max, .fbx and .obj.

    asked 5 Years ago by
    Avatar image of CG Helpline user vidal3d

    CGH Score : 12
    Last edited by vidal3d
    on 2012-09-27 16:22:01
    Add a Comment for this question
    Please Login or Register to add comment
    1 Answers :

    Use getFilenameType to retreive the file extension of a filename or filepath + filename. It basically justs works as a string parser and returns the .ext

    For example :

    getFilenameType "my_fbx_file.fbx"

    should give you back a string ".fbx"

    And for all the files in the folder, this is one way you can segregate them based on filetypes :

    for my_file in my_files do
        file_ext = getFilenameType my_file
        case of
          (file_ext==".max") : append max_files my_file
          (file_ext==".fbx") : append fbx_files my_file
          (file_ext==".obj") : append obj_files my_file
    print max_files
    print fbx_files
    print obj files

    answered 5 Years ago by
    Avatar image of CG Helpline user aaachooo

    Cambridge, United Kingdom
    CGH Score : 142
    Expertise : Maya; Python; Maxscript;
    thanks, that worked fine :)
    Add a Comment for this answer
    Please Login or Register to add comment

    Submit your Answer :


    Page rendered in 0.1203 seconds. Memory usage : 3.99MB.