'How to add a "not" action in cmd complex lines

I have made a program with which I download all my songs as mp3, however, unless I use the default name, it doesnt get saved as "song.mp3" but rather "song". Someone online suggested this :

for /R %x in (*) do ren "%x" *.mp3

But this also replaces the program's extension. converter.py now reads as converter.mp3

To make this easier and not have to rename the files all at once, I thought I would integrate this into the code by using the os module. But then the code wouldn't run the next time.

Is there a way to add a 'not' operator or something of the like so that the code replaces all extensions with '.mp3' except '.py'

What I have currently added to the program :

os.system('for /R %x in (*) do ren "%x" *.mp3')

os.system('ren converter.mp3 converter.py')



Solution 1:[1]

I feel like this would be easier to fix at download time rather than afterwards... but

for item in os.listdir():
   if os.path.isfile(item) and not item.endswith('.py'):
      os.rename(item, item + '.mp3')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1