Please help me out with this code as I am a beginner in python struggling . There needs to be one xyz file for every data file.The output format should be as follows : [ID]> [Year]>[Year-Month]>[Sub-ID]>[xyz.txt] The station ID for data is IN-023C Year to be determined based on the timestamp of the file Year-Month needs to be determined based on the timestamp of the file Substation-ID depends on the substation read (if in file I1 then it should be placed in folder Ipl1 if I2 then folder IPL2)xyz.txt has the same name as the file.txt same file name :[IN-023C]-I1-2018-12-01.txt code I have written :
import os
from shutil import copyfile
folder_path = '*C:\Users\P&K\Desktop\Assign\*'
os.chdir(folder_path)
for file in os.listdir(folder_path):
stationid = file[1:9]
year = file[14:17]
month = file[14:20]
substation = file[11:12]
if file == 'I1':
print ('Inverter1')
break
else:
print('Inverter2')
final_path = folder_path + '/' + stationid + '>' + year + '>'+'month'+'>'+'substation'+ '/' +
file + .txt'
copyfile(file, final_path)