3
$\begingroup$

My camera imported a background image. Is there any way to rename this image file with Python in Blender? That is, change its original name in Windows. Like "C_0V9.psd" to "C_0V1.psd".

1. List item

------------------------------------------------------

PS:

Knowing that the command is os.rename(), is it possible to write a complete code for require a folder directory? For example, how to refine the following code?

import os
filepath='C:\\Work\\Working\\0Head\\ImageBackground1\\'
os.rename('C_0V9.psd','C_0V9.psd')
$\endgroup$
4
  • $\begingroup$ use os.rename() learn more $\endgroup$
    – Karan
    Commented Jul 10, 2023 at 2:28
  • 1
    $\begingroup$ Thankfully, the full code is: import os os.rename('C:\\Work\\Working\\0Head\\ImageBackground1\\C_0V9.psd', 'C:\\Work\\Working\\0Head\\ImageBackground1\\C_0V91.psd') $\endgroup$
    – lee blues
    Commented Jul 10, 2023 at 3:00
  • $\begingroup$ @leeblues If this code is enough, what do you use it for? It will leave a Blender image with a wrong path to file that no longer exists. Why would you want to do this? $\endgroup$ Commented Jul 10, 2023 at 10:51
  • $\begingroup$ yes,I have a other code at the same time modified bpy.data.images["C_0V9.psd"].filepath, Just want to add to modify the system name, and I added the question, how to improve the code please? $\endgroup$
    – lee blues
    Commented Jul 11, 2023 at 0:20

1 Answer 1

3
$\begingroup$
import os

os.rename('C:\\Work\\Working\\0Head\\ImageBackground1\\C_0V9.psd', 'C:\\Work\\Working\\0Head\\ImageBackground1\\C_0V91.psd')
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .