Agustin Coronel
Agustin Coronel

Reputation: 287

how to get the lastest modified file in folder python django

i have this code, first i get the image from a input and then i create a copy in folder in this case 'tareas', then i need to print the name of that image, i can create the copy successfully but i can't get the name of the copy.

if request.method == "POST":
        uploaded_file = request.FILES['imagen']
        fs = FileSystemStorage()
        fs.save(uploaded_file.name, uploaded_file)

        caminodelarchivo = "C:/Users/Usuario/Documents/Django/Proyecto/imagenes/tareas"
        files = glob.glob(caminodelarchivo)
        ultimoarchivo = max(files, key=os.path.getctime)
        print ("El nombre es: ", ultimoarchivo)

Upvotes: 0

Views: 66

Answers (1)

weAreStarsDust
weAreStarsDust

Reputation: 2752

In your case filename stored in uploaded_file.name why you don't use it?

Upvotes: 2

Related Questions