Skip to content

Commit 5cb9096

Browse files
committed
exercise 7
1 parent d4ae3ca commit 5cb9096

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

2. os/exercise 7/README.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Exercise 7
2+
3+
Using the built-in os module create a directory called `images`. Then create two directories in this directory named `images_png` and `images_jpg`. Before creating each directory, check if such directory exists.
4+
5+
```python exercise.py
6+
import os
7+
8+
base_dir = 'images'
9+
10+
# add your solution here
11+
12+
for root, dirs, files in os.walk(base_dir):
13+
print(root)
14+
15+
```
16+
17+
## Expected result
18+
19+
```cmd
20+
images
21+
images/images_jpg
22+
images/images_png
23+
```

2. os/exercise 7/exercise.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import os
2+
3+
4+
base_dir = 'images'
5+
6+
# add your solution here
7+
8+
for root, dirs, files in os.walk(base_dir):
9+
print(root)

2. os/exercise 7/solution.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import os
2+
3+
base_dir = 'images'
4+
5+
# add your solution here
6+
7+
png_dir = os.path.join(base_dir, 'images_png')
8+
jpg_dir = os.path.join(base_dir, 'images_jpg')
9+
10+
if not os.path.exists(base_dir):
11+
os.mkdir(base_dir)
12+
13+
if not os.path.exists(png_dir):
14+
os.mkdir(png_dir)
15+
16+
if not os.path.exists(jpg_dir):
17+
os.mkdir(jpg_dir)
18+
19+
for root, dirs, files in os.walk(base_dir):
20+
print(root)

0 commit comments

Comments
 (0)