[Python] why is this code removing the file instead of renaming it?

Discussão em 'Python' iniciado por Stack, Junho 24, 2025.

  1. Stack

    Stack Membro Participativo

    I want to rename report.json but it is removing the file instead

    import os
    from pathlib import Path
    import json



    path =Path( r'C:\Users\Sajid\Desktop\cuckoo (3)\cuckoo\storage\analyses\3\reports')
    filename = os.path.join(path,"report.json")
    with open(filename) as json_file:
    data=json.load(json_file)
    var=(data['target']['file']['md5'])
    print(var)
    json_file.close()
    os.rename(filename,var)


    I expect this code to rename the file and not delete it

    Continue reading...

Compartilhe esta Página