1

I created this script a while ago and now I am trying to get it working again. I am using a .cmd file to run a python script I made.

Here is the contents of the .cmd file:

    @setlocal enableextensions & "C:/Program Files/Autodesk/Maya2012/bin/mayapy.exe" -x "%~f0" %* & goto :EOF

    import sys
    import time
    sys.path.append(r"C:\Users\Court\Desktop\Extra Space\Q8\Intro to 3D Scripting")
    import project_outline
    project = raw_input
    project_outline.kickstart(project)

    raw_input("Press enter to close this window.")

I will paste the the contents of the python script in a minute. The goal of this was to create a stand alone function that would organize files of certain types into specific folders. I enter the address of the source file and then it is supposed to do its thing. The issue I seem to have is that the python file fails to execute.

Here is the python script

    #bring in some important tools
    import os
    import sys
    import re
    import shutil


    # function to set up everything needed to sort the files
    def kickstart(project):
        #variable that will be used to create file names
        subGroup = ["mayaFiles", "maxFiles", "tgaImages", "jpgImages", "psdFiles", "udkFiles", "upkFiles"]
        #variable that will be used to identify file type
        fileExtension = [[".ma", ".mb"], [".max"], [".tga"], [".jpg"], [".psd"], [".udk"], [".upk"]]
        #creates a variable that holds the destination path for when folders are created
        path = "C:\Users\Court\Desktop\Extra Space\Q8\Intro to 3D Scripting\organizedFiles"
        #iterator
        i=0
        #iterate through each grouping, initiate subroutine to create fil folders and move files to the right folder
        for sg in subGroup:
            for extension in fileExtension[i]:
                fileList = fileFinder(project, extension)
                subfileFinder(path, project, sg, fileList)  
            i=i+1
    #defines a routine that will step through a designated folder and find files of certain types
    def fileFinder(project, fileExtension):
        fileList = []
        #for loop for stepping through a source folder
        for root, dirs, files in os.walk(project):
            #for loop for analyzing each file in the folder
            for name in files:
                #series of if statements that analyzes the file extension to see what kind of file it is and store it under the relevant variable
                if os.path.splitext(name)[1] == fileExtension:
                    fileList.append(os.path.join(root, name))
        return fileList

    #defines a routine that further analyzes the name of each file 
    def subfileFinder(path, project, subGroup, fileList):
        for name in fileList:
            INeedToMove = True
            for category in ["Char_", "Env_", "T_"]:
            #will try to match the name of the file to a string of characters
            #if the value of match is true
                if re.search(category, name):
                    INeedToMove = False
                        #attempt to create a directory with specific name
                        try:
                            print ("making directory for " + path + "/" + subGroup + "/" + category)
                            os.makedirs(path + "/"  + subGroup + "/" + category)
                        #if the directory can't be made, move on
                        except:
                            pass
                        print ("Moving " + name + " to " + path + "/" + subGroup + "/" + category)
                        location = (project + "/" + name)
                        destination = (path + "/" + subGroup + "/" + category)
                        try:
                            shutil.copy(location, destination)
                        except:
                            print ("Failed to move")
                    if INeedToMove:
                        try:
                            print ("Making directory for " + subGroup)
                            os.makedirs(path + "/" + subGroup)
                        #if the directory can't be made, move on
                        except:
                            pass
                        print ("Moving " + name + " to " + path + "/" + subGroup)
                        try:
                            shutil.copy((project + "/" + name), (path + "/" + subGroup + "/" + name))
                        except:
                            print ("Failed to move.")

I will really appreciate all the help I can get on this. I've tried everything I know to troubleshoot this. I am relatively new to scripting so I'm sure someone here can show me something to try that I might not have thought of. Thanks.

CT3D
  • 11
  • 1
  • 1
    Not sure, but this might help: http://stackoverflow.com/questions/4621255/how-do-i-run-a-python-program-in-the-command-prompt-in-windows-7 – Forivin Nov 08 '13 at 07:19
  • 3
    The script starts execution and then crashes or it does not run at all? Is there any error trace available? – orique Nov 08 '13 at 07:34

0 Answers0