I am trying to change the name of file using Python but the name does not change.
The program has to take a photo, save it, copy it to a server, change the name of copied photo and change the name of original photo. So, first of all I define a variable which is going to be a exact date and time. After that, I take a photo and save it like imagen.jpg Following, I copy imagen.jpg to other path (server path), and try change its name to the variable which I defined before. But the name does not change and the file is removed.
After that I change the name of original photo with the same function and the name is changed....I don't know why the copied photo doesn't change its name.
Here's the code:
import shutil
import picamera
import os
fecha = time.strftime("%c") # En esta variable se guarda la fecha actual y la hora para renombrar la foto guardada
camera.capture('/home/pi/Desktop/RaspAlarm/imagen.jpg')
print("Capturando foto")
time.sleep(5)
print("Copiando foto al servidor")
shutil.copy("/home/pi/Desktop/RaspAlarm/imagen.jpg", "/var/www/html/RaspAlarm/Fotos")
time.sleep(1)
os.listdir("/var/www/html/RaspAlarm/Fotos")
os.rename ("/var/www/html/RaspAlarm/Fotos/imagen.jpg", fecha)
print("Cambiando nombre al archivo")
os.rename ("/home/pi/Desktop/RaspAlarm/imagen.jpg", fecha)
time.sleep(1)
print("Foto guardada")
Could you help me? Thank you