Skip to content

Latest commit

 

History

History
31 lines (20 loc) · 1.4 KB

File metadata and controls

31 lines (20 loc) · 1.4 KB

Complete Labs 36 and 37

drawing

In labs 36 and 37 the shutil.move(), shutil.copy(), and shutil.copytree() functions were used to automate the transferring and/or renaming of files and directories.

Choose one of the scripts from either lab and upgrade it. Instead of copying/moving a SINGLE file or directory, let it do MULTIPLE!

Make a directory with a bunch of files and subdirectories in it. Use these for your code.

student@bchd:~$ mkdir ~/mycode/copyloops && cd ~/mycode/copyloops

student@bchd:~/mycode/copyloops$ touch file1 file2 file3 file4 file5 && mkdir ~/mycode/copyloops/dontmoveme

Your script should:

  • take input from a user for the files' SOURCE and for the files' DESTINATION
  • loop over all the files (file1 file2 file3 file4 file5) in the specified directory (~/mycode/copyloops/), but DON'T move the directory (dontmoveme)
  • copy the files to another location of your choosing.

So in a nutshell:

for everydangfile in SOURCE:
    if everydangfile != directory:
       movethatsucker(DESTINATION)

RECOMMENDED TOOLS:

  • os.listdir- returns a list of files/directories inside a directory.
  • os.path.isdir- returns True/False whether a specified path is a directory or not.