0

I wrote a program to iterate over the files of a folder and add the ".jpg" file extension to all files without any file extension. I tested the program on my computer and it works so far. I compiled the .py file to an .exe file using the auto-py-to-exe package to send the program to a friend who doesn't have python installed on her computer. When I tested the .exe file I found out that the program behaves differently and doesn't work anymore. The following code is what I wrote, if you uncomment the print command you can see different files when running the .py and .exe file

import os

files = os.listdir(os.path.dirname(os.path.abspath(__file__)))
for file in files:
    # print(file)
    split_tup = os.path.splitext(file)
    if split_tup[1] == '':
        os.rename(file, file + '.jpg')
# The input is just that the console doesn't shut down
a = input()

For auto-py-to-exe I used following command:

pyinstaller --noconfirm --onefile --console  "C:/mypath/jpg_wizard.py"

Is there a way I can change the auto-py-to-exe command/settings or an alternative code I can use to be able to run the program as an .exe file and get the same result as the .py file?

Dima Chubarov
  • 16,199
  • 6
  • 40
  • 76

1 Answers1

0

Found a solution that works:

import os

path = os.getcwd()
folder = os.scandir(path)
for file in folder:
    file = file.name
    split = os.path.splitext(file)
    if split[1] == '':
        os.rename(file, file + '.jpg')
        print(file + '.jpg')

Now I use the current working directory as path and iterate over the files I find with os.scandir(path).