rename multiple files in directory using json sources

   # Input json

import json
with open('C:\\Users\desktop\item.json')
data = json.load(f)
print(data)

 # Output json

{
    '1': 'C:\\Users\desktop\clip\13324.jpg',
    '2': 'C:\\Users\desktop\clip\133299.jpg',
    '3': 'C:\\Users\desktop\clip\133217.jpg',
}

   # input file_names

import os
file_path = 'C:\\Users\desktop\label'
file_names = os.listdir(file_path)
file_names

   # output file_names

'1.xml',
'1.txt',
'2.xml',
'2.txt',
'3.txt',
'3.txt',

I would like to change my file_names using json sources
For example
1.xml -> 13324.xml
1.txt -> 13324.txt
2.xml -> 133299.xml
2.txt -> 133299.txt
3.xml -> 133217.xml
3.txt -> 133217.txt

I tried to use for loop but can’t figure out how to match and rename the files. please help

For analyzing files name I recommend using the pathlib module. Path objects have methods to get different parts of the file name, the parent directory, and so on. The can also be used to rename files.

From the description I’m not sure how you want to rename the files, like how to recognize source files and how to determine the new name. If you’d like help with that, please describe it a bit more precisely.