1

I am very new to Python. I am curious to how I would be able to copy some files from my directory to another Users directory on my computer using python script? And would I be correct in saying I need to check the permissions of the users and files? So my question is how do I send files and also check the permissions at the same time

Nikki Rae
  • 49
  • 5

2 Answers2

2

You want to use shutil.copy(src, destination), you can find the docs here: https://docs.python.org/2/library/shutil.html#shutil.copy

You can also read here on how to access file permissions in python: Checking File Permissions in Linux with Python

Determining Whether a Directory is Writeable

Community
  • 1
  • 1
Kieran
  • 286
  • 5
  • 12
1

shutil is a very usefull thing to use when copying files. I once needed to have a python script that moved all .mp3 files from a directory to a backup, deleted the original directory, created a new once, and moved the .mp3 files back in. shutil was perfect for thise.

The formatting for the command is how @Kieran has stated earlier.

If you're looking to keep file metadata, then use shutil.copy2(src, dest), as that is the equivalent of running copy() and copystat() one after another.

RedXTech
  • 406
  • 2
  • 7
  • 17