-1
I am creating a script in python to convert all the files of a folder into another format informed by the user, but I wanted to ask only once the location to save the files. I tried to use askdirectory() but it gives a strange error that the directory where the files are being the same where they will be saved even adding to different variables.
import glob
import img2pdf
from tkinter import Tk
from tkinter.filedialog import askdirectory
def img_to_pdf(arq, savefile):
with open(f"{str(arq)[0:-4]}.pdf", "wb") as f:
f.write(img2pdf.convert(arq))
def convert(filelocal, inpt, outpt, savefile):
path = Path(str(filelocal))
for arq in path.glob('*'):
if arq.endswith(str(inpt)):
if inpt == ".png" and outpt == ".pdf":
img_to_pdf(arq, savefile)
def localfile():
Tk().withdraw()
filelocal = askdirectory()
return filelocal
def filesave():
Tk().withdraw()
savefile = askdirectory()
return savefile
if __name__ == '__main__':
inpt = ".png"
outpt = ".pdf"
filelocal = localfile()
savefile = filesave()
convert(filelocal, inpt, outpt, savefile)
Any suggestions how I can fix this problem? Because the solutions I have found so far only help if it is to save a single file, so for each file inside the folder, it would ask again the location. What I want is to set a place to save by default.