AtBS 9 Organizing Files Flashcards

1
Q

What module lets you copy, move, rename or delete files in your Python programs?

A

Shutil

Shell Utilities

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Shutil copy syntax

A

shutil.copy(‘ Source.txt path,

Destintation Path

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Shutil copy example

A

shutil.copy( ‘C:\TestFolder \sonnet29.txt’,

‘C:\TestFolder\FirstFolder’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does shutil .copytree() do?

A

It copies a folder and every folder and file within it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

When using the shutil copy function what happens when you paste a file into a folder with a file by that name?

A

It gets copied over

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to move a file with Python?

A

shutil.move (file path current including file, file path new)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does shutil stand for?

A

It stand for shell utility

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

When using the shutil function to move a file what do you need to watch out for?

A

When moving the file make sure the new file path is an actual location or the existing file will get renamed to that file.

pg 199

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How to delete a single file with Python?

A

os.unlink (path)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to delete an empty folder with Python?

A

os.rmdir(path)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How to delete a folder with files in it in Python?

A

shutil.rmtree (path)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is dangerous about using shutil to remove files?

A

Shutil deletes files permanently

Use send2trash module to send files to trash

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the syntax for the send2trash function

A

send2trash .send2trash (path)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the downside of using the send2trash function instead of shutil or os?

A

send2trash does not free up disk space like shutil or os do.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What function can return the subfolder and files in a folder?

What module is it in?

A

os.walk

need to import os file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly