-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_parsing.py
More file actions
executable file
·34 lines (28 loc) · 1.25 KB
/
file_parsing.py
File metadata and controls
executable file
·34 lines (28 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#----------------------------------------------------------------------------------------------#
# File Parsing in Py
#----------------------------------------------------------------------------------------------#
import os
os.chdir('/home/jp/Downloads/learn_python3/Videos')
print(os.getcwd())
for file in os.listdir():
#print(file)
# spliting the file extension
#print(os.path.splitdrive(file))
# retriving the file name and extension separately
f_name , f_exte = os.path.splitext(file)
#print(f_name,f_exte)
#----------------------------------------------------------------------------------------------#
# here you can aslo spilit the f_name oe f_extention
#----------------------------------------------------------------------------------------------#
for file in os.listdir():
f_name , f_exte = os.path.splitext(file)
f_title, f_course , f_chapter =f_name.split('-')
#print(f_title)
#using the strip() fun
f_title=f_title.strip()[1:].zfill(2) # use to fill the zero befor the digiit
f_course=f_course.strip()
f_chapter=f_chapter.strip()
print('{}-{}-{}'.format(f_title,f_course,f_chapter))
#Renaming the file
new_name= '{}-{}'.format(f_title,f_chapter)
os.rename(file,new_name)