Saturday, May 22, 2021

Using shutil module to move and copy files

Script

#!/usr/local/bin/python3.5

from shutil import copy, copyfile, move

print("Copy a file from /tmp to /Python-scripts")
print("----------------------------------------")
copy('/tmp/Nagpur-2008-K26.txt', '/Python-scripts/Memorable-Tests')

print("Move a file from /tmp to /Python-scripts")
print("----------------------------------------")
move('/tmp/Bangalore-2010-K27.txt', '/Python-scripts/Memorable-Tests')

print("Make a copy of a file")
print("---------------------")
copyfile('/Python-scripts/Memorable-Tests/Kolkata-2001-K10.txt', '/Python-scripts/Memorable-Tests/Laxman-epic.txt')
print()
print()


Before executing the script

ip-172-31-24-12.us-west-2.compute.internal: /Python-scripts/Memorable-Tests >
ip-172-31-24-12.us-west-2.compute.internal: /Python-scripts/Memorable-Tests > ls -altr Bangalore*
ls: cannot access Bangalore*: No such file or directory
ip-172-31-24-12.us-west-2.compute.internal: /Python-scripts/Memorable-Tests >
ip-172-31-24-12.us-west-2.compute.internal: /Python-scripts/Memorable-Tests > ls -altr Nagpur*
ls: cannot access Nagpur*: No such file or directory
ip-172-31-24-12.us-west-2.compute.internal: /Python-scripts/Memorable-Tests >
ip-172-31-24-12.us-west-2.compute.internal: /Python-scripts/Memorable-Tests > ls -altr Laxman*
ls: cannot access Laxman*: No such file or directory
ip-172-31-24-12.us-west-2.compute.internal: /Python-scripts/Memorable-Tests > cd /tmp
ip-172-31-24-12.us-west-2.compute.internal: /tmp >
ip-172-31-24-12.us-west-2.compute.internal: /tmp > vi Bangalore-2010-K27.txt
ip-172-31-24-12.us-west-2.compute.internal: /tmp >
ip-172-31-24-12.us-west-2.compute.internal: /tmp >
ip-172-31-24-12.us-west-2.compute.internal: /tmp >
ip-172-31-24-12.us-west-2.compute.internal: /tmp >
ip-172-31-24-12.us-west-2.compute.internal: /tmp > vi Nagpur-2008-K26.txt
ip-172-31-24-12.us-west-2.compute.internal: /tmp >
ip-172-31-24-12.us-west-2.compute.internal: /tmp >
ip-172-31-24-12.us-west-2.compute.internal: /tmp > cat Bangalore-2010-K27.txt

Sachin Tendulkar played one of the most important innings of his career, a belligerent 214
that helped India beat Australia convincingly by 7 wickets, and helped keep Ricky Ponting's
dubious record of no victory on Indian soil as captain of Australia.
Tendulkar went from 93 to 99 and from 99 to 105 by hitting two sixes off Nathan Hauritz
in keeping with his son Arjun's advice to hit a six when getting to his century.

ip-172-31-24-12.us-west-2.compute.internal: /tmp >
ip-172-31-24-12.us-west-2.compute.internal: /tmp > cat Nagpur-2008-K26.txt

The Test match in which Ricky Ponting made the most horrible decision in his captaincy tenure
by introducing his part timers to bowl instead of employing his fast bowlers, to keep up with
the overrate, thereby ultimately costing him and Australia the Test match and the series.

ip-172-31-24-12.us-west-2.compute.internal: /tmp >
ip-172-31-24-12.us-west-2.compute.internal: /tmp >


Execution

Copy a file from /tmp to /Python-scripts
----------------------------------------
Move a file from /tmp to /Python-scripts
----------------------------------------
Make a copy of a file
---------------------


After executing the script

ip-172-31-24-12.us-west-2.compute.internal: /Python-scripts/Memorable-Tests >
ip-172-31-24-12.us-west-2.compute.internal: /Python-scripts/Memorable-Tests > ls -altr Bangalore-2010-K27.txt
-rw-r--r--. 1 root root 423 Mar  2 15:19 Bangalore-2010-K27.txt
ip-172-31-24-12.us-west-2.compute.internal: /Python-scripts/Memorable-Tests >
ip-172-31-24-12.us-west-2.compute.internal: /Python-scripts/Memorable-Tests > cat Bangalore-2010-K27.txt

Sachin Tendulkar played one of the most important innings of his career, a belligerent 214
that helped India beat Australia convincingly by 7 wickets, and helped keep Ricky Ponting's
dubious record of no victory on Indian soil as captain of Australia.
Tendulkar went from 93 to 99 and from 99 to 105 by hitting two sixes off Nathan Hauritz
in keeping with his son Arjun's advice to hit a six when getting to his century.

ip-172-31-24-12.us-west-2.compute.internal: /Python-scripts/Memorable-Tests >
ip-172-31-24-12.us-west-2.compute.internal: /Python-scripts/Memorable-Tests > ls -altr Nagpur-2008-K26.txt
-rw-r--r--. 1 root root 280 Mar  2 15:23 Nagpur-2008-K26.txt
ip-172-31-24-12.us-west-2.compute.internal: /Python-scripts/Memorable-Tests >
ip-172-31-24-12.us-west-2.compute.internal: /Python-scripts/Memorable-Tests > cat Nagpur-2008-K26.txt

The Test match in which Ricky Ponting made the most horrible decision in his captaincy tenure
by introducing his part timers to bowl instead of employing his fast bowlers, to keep up with
the overrate, thereby ultimately costing him and Australia the Test match and the series.

ip-172-31-24-12.us-west-2.compute.internal: /Python-scripts/Memorable-Tests >
ip-172-31-24-12.us-west-2.compute.internal: /Python-scripts/Memorable-Tests > ls -altr Laxman-epic.txt
-rw-r--r--. 1 root root 631 Mar  2 15:23 Laxman-epic.txt
ip-172-31-24-12.us-west-2.compute.internal: /Python-scripts/Memorable-Tests >
ip-172-31-24-12.us-west-2.compute.internal: /Python-scripts/Memorable-Tests > cat Laxman-epic.txt

Kolkata 2001 stirs amazing memories of an incredible Test match that had people grappling for superlatives
while trying to reconcile on what transpired over five days of an unbelievable Test match.   India, after
trailing by 274 runs in the first innings against a star studded Australian team, turned the match and the
series on its head through a once-in-a-lifetime breathtaking performance from VVS Laxman, who with a
tremendous amount of support from Karnataka hero Rahul Dravid stunned Australia in a magnificent partnership
of 376, on his way to a classic 281, and helped India crush Australia by 174 runs on the last day.

ip-172-31-24-12.us-west-2.compute.internal: /Python-scripts/Memorable-Tests >
ip-172-31-24-12.us-west-2.compute.internal: /Python-scripts/Memorable-Tests >





No comments:

Post a Comment