I'm trying to write my first Python script, and it is not going well.
I am trying to copy an entire local directory on my Ubuntu machine and place it and its contents in a different on my OS. I did some research and found distutils.dir_util.copy_tree(src,dst)
should do just that.
This is the contents of my backup_images.py file:
import os
import sys
src = '/nodeGit/code/assets/images'
dst = '/usr/images_backup'
distutils.dir_util.copy_tree(src,dst)
When I run it, I get error(s) on every line. When I run ./backup_images.py
in terminal, this is the output:
./backup_images.py: line 1: src: command not found
./backup_images.py: line 2: dst: command not found
./backup_images.py: line 4: syntax error near unexpected token `src,dst'
./backup_images.py: line 4: `distutils.dir_util.copy_tree(src,dst)'
If I run the same command with sudo (sudo ./backup_images.py
), I get completely different errors:
./backup_images.py: 1: ./backup_images.py: src: not found
./backup_images.py: 2: ./backup_images.py: dst: not found
./backup_images.py: 4: ./backup_images.py: Syntax error: word unexpected (expecting ")")
Based on the first couple errors of this, (src: not found
,dst: not found
), it seems Python isn't able to find the directories I assigned the src
and dst
files to. Is this correct?
Because of the changing errors, I'm unsure of how to fix my code.