THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 05/07/2012 at 13:22, xxxxxxxx wrote:
I'm trying to rename a rendered list of image files that correspond to a list of objects in a c4d scene using os.rename. My test (DRYRUN=True) works just right to rename the files, but when I try to actually rename the files (DRYRUN=True) I get this error: OSError: [Errno 2] No such file or directory.
The error references this line: os.rename(PreDirList,nameT).
I'm not sure if os.rename works with OSX (I'm on a Mac). Suggestions anyone? Here is the code:
import c4d, math, os
from c4d import gui, utils
def main() :
# Get the root xref's into a list
c4d.CallCommand(12112) #Select all root objects
Selected = doc.GetActiveObjects(0)
theCount = len(Selected)
xrefSel = []
for ListOb in Selected:
nameT = ListOb.GetName() #return the name of an object
if nameT[0:4] == "xref":
#print nameT
xrefSel.append(ListOb)
#print xrefSel
# Create a list of files from the current directory who's last 4 characters
# as lowercase are either '.jpg' or '.png'
path = "/Volumes/Argo3D/Render Index/Universal/Accessory_catalog_Scene/"
#path=c4d.storage.LoadDialog(c4d.FILESELECTTYPE_ANYTHING, "Please choose a folder", c4d.FILESELECT_DIRECTORY)
dirList=os.listdir(path)
dirList = dirList [1:]
#print path
files = [f for f in dirList if f[-4:] in ('.jpg','.png') ] #Filer out the image files into a new list
#print files
# Rename images to the same name as the xrefs in order
DRYRUN=False #!!!!!!!!!!!!!Change this to False when ready to change names!!!!!!!!!!!!!!!!
x = 1
for ListObj in xrefSel:
nameT = ListObj.GetName() #return the name of an object
nameT = nameT[9:-4] + "_" + "%04d" % (x,) + ".jpg"
#print nameT
PreDirList = dirList[x-1]
if DRYRUN:
print "Would rename " + PreDirList + " to " + nameT
else:
print "Renaming " + PreDirList + " to " + nameT
os.rename(PreDirList,nameT)
x += 1
if __name__=='__main__':
main()