More File Operations using Python

  • To check if a file exists .

screenshot-69.png

Screenshot (68)

The above code checks if there is a file called p.py in the current directory and prints True or False. Initially the code checks for a file called k.py which is not present .So it prints False. Then in the 2 nd code, it checks for a file called p.py which is present. So it prints True.

  • Rename a file.

screenshot-71.png

Here p.py is the old name .’renamed.py’ is the new name.

  • Delete a file.

screenshot-72.png

The above code removes or deletes renamed.py file.

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

Powered by WordPress.com.

Up ↑

%d bloggers like this: