-
Notifications
You must be signed in to change notification settings - Fork 0
/
exercise_9.py
52 lines (52 loc) · 1.9 KB
/
exercise_9.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import os
print("******************************** Welcome to file name arranger **********************************")
dic=os.getcwd()
print(f"you are in this directory :- {dic}")
dic2 = str(input('Enter the name of the directory you want get access to :- '))
os.chdir(dic2)
die=os.getcwd()
print(f"now you are in :- {die}")
lis=os.listdir()
opt=int(input('1.Do you want to see all the file inside this directory \n2.Do you want to search the name of file costmly\n'))
if opt==1:
print(lis)
elif opt ==2:
name_f=str(input("enter the name of the file you want to search :- "))
def ser(lis,name_f):
for i in range (len(lis)):
if lis[i]== name_f:
return True
return False
if ser(lis, name_f):
print("Found")
else:
print("Not Found")
else :
print('invalid option picked')
print("########################## Hello sir/mam what you want to do with the file in this directory ################################")
option=int(input("1.want to pritify the file by capatilising the names of the file\n2.want to arange the file name and arrange it numarically\n3.custom file nameing\n"))
if option == 1:
lis_n=[]
for items in lis:
lis_n.append(items.upper())
for i in range (len(lis)):
os.rename(lis[i],lis_n[i])
print(os.listdir())
elif option == 2:
num = 0
lis_n = []
lis_new=[]
for i in range(len(lis)):
lis_n= lis[i].split('.')
for i in range (len(lis)):
lis_new=f"{lis_n[num]}.{lis_n[num+1]}"
num = num+2
for i in range (len(lis)):
os.rename(lis[i],lis_new[i])
print(lis_n)
elif option==3:
old_name=str(input('enter the intial name of the file :-'))
new_name=str(input('enter the new name of the file you want to change the name of :- '))
os.rename(old_name,new_name)
else:
print("in-valid option choose")