File tree Expand file tree Collapse file tree 4 files changed +58
-41
lines changed Expand file tree Collapse file tree 4 files changed +58
-41
lines changed Original file line number Diff line number Diff line change
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
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 4
4
#
5
5
6
6
import os
7
+ import shutil
7
8
from os import path
9
+ from shutil import make_archive
10
+ from zipfile import ZipFile
11
+
8
12
9
13
def main ():
10
14
# make a duplicate of an existing file
11
- if path .exists ("textfile.txt" ):
15
+ if path .exists ("textfile.txt.bak " ):
12
16
# get the path to the file in the current directory
13
-
17
+ src = path .realpath ("textfile.txt.bak" )
18
+
14
19
# let's make a backup copy by appending "bak" to the name
15
-
20
+ # dst = src + ".bak"
21
+ # shutil.copy(src, dst)
22
+
16
23
# rename the original file
17
-
24
+ # os.rename(src, "newfile.txt")
25
+
18
26
# now put things into a ZIP archive
27
+ # root_dir, _ = path.split(src)
28
+ # make_archive("archive", "zip", root_dir)
19
29
20
30
# 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
+
21
35
22
-
23
36
if __name__ == "__main__" :
24
37
main ()
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments