how to copy multiple file names in python, from one file to another? win10

  file, operating-system, python, rename, windows

Im trying to copy file names in python, and automate it
the copying part works fine, but the automation part doesnt

i have this script that takes the names of files from a folder
and applies it to files in another folder:

import os

x = 0

while x < 2:
sound_files = ‘C:Usersm8Desktopbf testfir’

files_just_files = []

files = []

for r, d, f in os.walk(sound_files):
    for file in f:
            files.append(os.path.join(r, file))
            files_just_files.append(file)



soooooooooooooooooooooond = files_just_files[x]
soooooooooooooooooooooond_dir = files[x]

#print(soooooooooooooooooooooond)
print(soooooooooooooooooooooond_dir)


sound_files2 = 'C:Usersm8Desktopbf testsec'

files_just_files2 = []

files2 = []

for r, d, f in os.walk(sound_files2):
    for file2 in f:
        if 'p' in file2:
            files2.append(os.path.join(r, file2))
            files_just_files2.append(file2)


soooooooooooooooooooooond2 = files_just_files2[x]
soooooooooooooooooooooond2_dir = files2[x]

#print(soooooooooooooooooooooond2)
print(soooooooooooooooooooooond2_dir)
os.rename(soooooooooooooooooooooond_dir, soooooooooooooooooooooond2_dir)

x += 1

but whenever i run it it keeps giving me this error:

C:Usersm8Desktopbf testfirpeeeeeeeeen - Copy (2).wav
C:Usersm8Desktopbf testsecdesktop.ini
Traceback (most recent call last):
  File "C:GamesGrand Theft Auto Vstuffbububuu.py", line 45, in <module>
    os.rename(soooooooooooooooooooooond_dir, soooooooooooooooooooooond2_dir)
FileExistsError: [WinError 183] Cannot create a file when that file already exists: 'C:Usersm8Desktopbf testfirpeeeeeeeeen - Copy (2).wav' -> 'C:Usersm8Desktopbf testsecdesktop.ini'

but there are no files named ‘desktop.ini’ in that folder, so what should i do?

thanks for anyone that can help!

Source: Windows Questions

LEAVE A COMMENT