I have 5 excel files in a folder, which I want to edit one by one and one by one means, one the next file only the previous file is closes.
So first I read all the files in a folder using glob.
inputsFiles = glob.glob('Sub_Inputs/[a-z]*xlsx')
output
['Sub_Inputs\\Buses.xlsx', 'Sub_Inputs\\Load_Profile.xlsx', 'Sub_Inputs\\Solar_Profile.xlsx', 'Sub_Inputs\\Time_frame.xlsx', 'Sub_Inputs\\Wind_Profile.xlsx']
after that I opened them:
for i in inputsFiles:
print('Please fill the details related to ' + os.path.basename(i)[:-5])
# print(i)
os.system("start EXCEL.EXE "+i)
But this will open all the files. I tried to check if the file is already open or not but that is not working in this condition:
try:
with open("filename", "r") as file:
# Print the success message
print("File has opened for reading.")
# Raise error if the file is opened before
except IOError:
print("File has opened already.")
this is not working, can anyone please help? I want to open the file only when the previous one is closed.