I have written the following python code in the jupyter notebook with file name as deletion.ipynb:
import os
PATH=os.getcwd()
print("Current Working Directory is: ", PATH)
os.remove(PATH+"\Details.xlsx")
Now, I have created an executable file by first convert this deletion.ipynb file into deletion.py file using !jupyter nbconvert --to script deletion.ipynb and then convert this deletion.py file into .exe by using !pyinstaller deletion.py. Now, an executable file is created in path \dist\deletion\deletion.exe.
When I try to run this executable file then console gets open and then closed suddenly without deleting the file Details.xlsx. I have already put Details.xlsx file in path \dist\deletion so that it should take the file from the current working directory where the executable is, But it is unable to delete the file.
Can anyone please help me how to delete a file by using an executable file which is created from python code. Any help would be appreciated.
PATHinto a file in a known location to check that you have the correct path? - mozwayos.getcwd()to detect the location of executable from where it is executed and put that file in that path. I have got one solution from here to delete file by making batch file from here: stackoverflow.com/questions/58502457/… but don't know why my code is not working. - ankit