-
Notifications
You must be signed in to change notification settings - Fork 0
/
os and glob tut for data load (1).py
106 lines (56 loc) · 1.57 KB
/
os and glob tut for data load (1).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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python
# coding: utf-8
# In[18]:
# loading modules
import os
import glob
import numpy as np
# In[2]:
# getting current directory of working
os.getcwd()
# In[4]:
# can list all the items using os.listdir() command
os.listdir()
# In[13]:
# we can use glob to files of the same pattern using UNIX type rules
print('#no1.\n')
# putting complete path returns that path
files1 = glob.glob('submission1.csv')
for file in files1:
print(file)
print('\nend #no1.\n')
print('start #no2.\n')
#using * operation this will return all files or folders in current directory
files2 = glob.glob('*')
for file in files2:
print(file)
print('\nend #no2.\n')
print('start #no3.\n')
# using *[0-9] returns range of files with this paths in 0-9 digits
files3 = glob.glob('*[0-9].*')
for file in files3:
print(file)
print('\n end #no3.\n')
# In[14]:
# recursive method can also be used to find subdirectories
# Returns a list of names in list files.
print("Using glob.glob()")
files4 = glob.glob('**/*.*',
recursive = True)
for file in files4:
print(file)
# In[25]:
# printing the no.of file with extension
for i,file in enumerate(files1):
print('{}:{}'.format(i,file))
# using os.path.basename to extract name of file
name = os.path.basename(file)
print(name)
# now apply os.path.splittext to split name and extension
split = os.path.splitext(name)[0]
print(split)
# printing individual letter
for letter in split:
print(letter)
# In[ ]:
# In[ ]: