AtBS 9 Organizing Files Flashcards
What module lets you copy, move, rename or delete files in your Python programs?
Shutil
Shell Utilities
Shutil copy syntax
shutil.copy(‘ Source.txt path,
Destintation Path
Shutil copy example
shutil.copy( ‘C:\TestFolder \sonnet29.txt’,
‘C:\TestFolder\FirstFolder’)
What does shutil .copytree() do?
It copies a folder and every folder and file within it.
When using the shutil copy function what happens when you paste a file into a folder with a file by that name?
It gets copied over
How to move a file with Python?
shutil.move (file path current including file, file path new)
What does shutil stand for?
It stand for shell utility
When using the shutil function to move a file what do you need to watch out for?
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 to delete a single file with Python?
os.unlink (path)
How to delete an empty folder with Python?
os.rmdir(path)
How to delete a folder with files in it in Python?
shutil.rmtree (path)
What is dangerous about using shutil to remove files?
Shutil deletes files permanently
Use send2trash module to send files to trash
What is the syntax for the send2trash function
send2trash .send2trash (path)
What is the downside of using the send2trash function instead of shutil or os?
send2trash does not free up disk space like shutil or os do.
What function can return the subfolder and files in a folder?
What module is it in?
os.walk
need to import os file