on-internet
← Community

Using Python's shutil to create a directory if it does not already exist

Stack Overflow ·

I have a program that currently copies a file from my computer to other computers on the network. This functions just fine if the other computers already have the directory specified. Some of the computers may not already have the specified directory. In this case, how could I create the directory if it does not exist and then copy the file into the new directory? Would shutil.copytree() work? Here is a portion of my current program: import fileinput import shutil def copyerror(): print("Cannot connect to " + servername + ".") def copyfiles(servername): source = os.listdir("C:/Users/jm/Desktop

Comments

Sign in or sign up to comment and upvote.

No comments yet.