8000 Remove unused files and add Chapter 11.4 challenge solution · tsrajar/python-basics-exercises@7accce6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7accce6

Browse files
committed
Remove unused files and add Chapter 11.4 challenge solution
1 parent 7110008 commit 7accce6

19 files changed

+27
-120
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# 11.4 Challenge: Move All Image Files To a New Directory
2+
# Solution to Challenge
3+
4+
from pathlib import Path
5+
6+
# Change this path to match the location on your computer
7+
documents_dir = (
8+
Path.home() /
9+
"python-basics-exercises" /
10+
"ch11-file-input-and-output" /
11+
"practice_files" /
12+
"documents"
13+
)
14+
15+
# Create an images/ directory in your home directory
16+
images_dir = Path.home() / "images"
17+
images_dir.mkdir(exist_ok=True)
18+
19+
# Search for image files in the documents directory and move
20+
# them to the images/ directory
21+
for path in documents_dir.rglob("*.*"):
22+
if path.suffix.lower() in [".png", ".jpg", ".gif"]:
23+
path.replace(images_dir / path.name)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Yo dad, what's up?
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1,2,3,4,5
2+
a,b,c,d,e
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
42

ch11-file-input-and-output/practice_files/example.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

ch11-file-input-and-output/practice_files/pastimes.csv

Lines changed: 0 additions & 5 deletions
This file was deleted.

ch11-file-input-and-output/practice_files/poem.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

ch11-file-input-and-output/practice_files/tabbed wonka.csv

Lines changed: 0 additions & 4 deletions
This file was deleted.

ch11-file-input-and-output/practice_files/wonka.csv

Lines changed: 0 additions & 4 deletions
This file was deleted.

ch11-file-input-and-output/sample_csv.csv

Lines changed: 0 additions & 101 deletions
This file was deleted.

0 commit comments

Comments
 (0)
0