Python Newbie Needs Help Copying Files from Windows to Linux

Hello,

I’m a first time GitHub user so please forgive my mistakes!

I’m also a Python newbie and I’d like some help to copy some Windows folders and files to a Centos 8 filesystem.
In Windows I have:
C:\folder1\file1, C:\folder2\folder3\file2, C:\folder4\folder5\folder6\file3, etc.

I’d like to copy these folders including sub-folders and files to my Centos 8 filesystem and replicate the directory layout like this on my Centos 8 machine:

/mystuff/folder1/file1, /mystuff/folder2/folder3/file2, /mystuff/folder4/folder5/folder6/file3, etc.

A little Python code snippet to do this would be much appreciated.

Thanks in advance!

-SR

You can use shutil.copytree() for that, by calling it with each of the top level directories as src in turn (in your example: folder1, folder2, folder4), and /mystuff/ as dest.

However if you already have a CentOS system it might be easier to just use the rsync command.

Either way you will first have to mount your Windows file system in the running CentOS system (most likely there’s a GUI option, but that depends on your configuration).

Hi airtower-luna,

The shutil.copytree() works great, thanks for your help :slight_smile:

-SR

1 Like