8000 Using filesystem shell methods · neryuuk/learning-python@013bf2a · GitHub
[go: up one dir, main page]

Skip to content

Commit 013bf2a

Browse files
committed
Using filesystem shell methods
1 parent 2a78a38 commit 013bf2a

File tree

4 files changed

+58
-41
lines changed

4 files changed

+58
-41
lines changed

Ch3 - Files/newfile.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
This is some text
2+
This is some text
3+
This is some text
4+
This is some text
5+
This is some text
6+
This is some text
7+
This is some text
8+
This is some text
9+
This is some text
10+
This is some text
11+
This is some new text
12+
This is some new text
13+
This is some new text
14+
This is some new text
15+
This is some new text
16+
This is some new text
17+
This is some new text
18+
This is some new text
19+
This is some new text
20+
This is some new text

Ch3 - Files/shell_finished.py

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

Ch3 - Files/shell_start.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,34 @@
44
#
55

66
import os
7+
import shutil
78
from os import path
9+
from shutil import make_archive
10+
from zipfile import ZipFile
11+
812

913
def main():
1014
# make a duplicate of an existing file
11-
if path.exists("textfile.txt"):
15+
if path.exists("textfile.txt.bak"):
1216
# get the path to the file in the current directory
13-
17+
src = path.realpath("textfile.txt.bak")
18+
1419
# let's make a backup copy by appending "bak" to the name
15-
20+
# dst = src + ".bak"
21+
# shutil.copy(src, dst)
22+
1623
# rename the original file
17-
24+
# os.rename(src, "newfile.txt")
25+
1826
# now put things into a ZIP archive
27+
# root_dir, _ = path.split(src)
28+
# make_archive("archive", "zip", root_dir)
1929

2030
# more fine-grained control over ZIP files
31+
with ZipFile("test_zip.zip", "w") as newzip:
32+
newzip.write("newfile.txt")
33+
newzip.write("textfile.txt.bak")
34+
2135

22-
2336
if __name__ == "__main__":
2437
main()

Ch3 - Files/textfile.txt.bak

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
This is some text
2+
This is some text
3+
This is some text
4+
This is some text
5+
This is some text
6+
This is some text
7+
This is some text
8+
This is some text
9+
This is some text
10+
This is some text
11+
This is some new text
12+
This is some new text
13+
This is some new text
14+
This is some new text
15+
This is some new text
16+
This is some new text
17+
This is some new text
18+
This is some new text
19+
This is some new text
20+
This is some new text

0 commit comments

Comments
 (0)
0