{"id":6741,"date":"2025-01-20T07:09:08","date_gmt":"2025-01-20T07:09:08","guid":{"rendered":"https:\/\/ubiq.co\/tech-blog\/?p=6741"},"modified":"2025-01-20T09:35:49","modified_gmt":"2025-01-20T09:35:49","slug":"how-to-copy-files-in-python","status":"publish","type":"post","link":"https:\/\/ubiq.co\/tech-blog\/how-to-copy-files-in-python\/","title":{"rendered":"How to Copy Files in Python"},"content":{"rendered":"\n<p>Often software developers need to copy files and directories from one disk location to another. Typically, they use terminal commands such as cp or mv for this purpose. But sometimes, you may need to copy files within your Python application\/website at the click of a button or when some other event is triggered. In this case, you will need to programmatically copy files using Python. This is also true in case you need to copy files in bulk. There are several ways to solve this problem. In this article, we will learn how copy files in Python.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-copy-files-in-python\/#How_to_Copy_Files_in_Python\" >How to Copy Files in Python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-copy-files-in-python\/#1_Using_Shutil_Module\" >1. Using Shutil Module<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-copy-files-in-python\/#Using_shutilcopyfile_function\" >Using shutil.copyfile function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-copy-files-in-python\/#Using_shutilcopy_function\" >Using shutil.copy function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-copy-files-in-python\/#Using_shutilcopy2_function\" >Using shutil.copy2 function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-copy-files-in-python\/#Using_shutilcopyfileobj\" >Using shutil.copyfileobj<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-copy-files-in-python\/#2_Using_OS_Module\" >2. Using OS Module<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-copy-files-in-python\/#Using_ospopen_function\" >Using os.popen function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-copy-files-in-python\/#Using_ossystem_function\" >Using os.system function<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-copy-files-in-python\/#3_Using_Subprocess_Module\" >3. Using Subprocess Module<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-copy-files-in-python\/#Using_subprocesscall\" >Using subprocess.call<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-copy-files-in-python\/#Using_subprocesscheck_output\" >Using subprocess.check_output<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-copy-files-in-python\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Copy_Files_in_Python\"><\/span>How to Copy Files in Python<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Here are the different ways to copy files in Python.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Using_Shutil_Module\"><\/span>1. Using Shutil Module<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Shutil is a popular Python module that offers many high-level functions to copy or delete one or more files and folders. There are several different functions specifically available to copy files. Let us look at the important ones.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Using_shutilcopyfile_function\"><\/span>Using shutil.copyfile function<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The copyfile function easily copies file contents from one location to another. However, it does not copy file metadata. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">shutil.copyfile(source, destination, *, follow_symlinks=True)<\/pre>\n\n\n\n<p>In the above command, you need to specify the source and destination paths for the file, as strings. The remaining 2 arguments are optional. If the follow_symlink option is true, then a file copy is created in destination, if the source is a symbolic link. Else the destination will also be a symbolic link.<\/p>\n\n\n\n<p>Please note, the system user executing this command must have write permission for destination directory. Otherwise, it will raise OSError. Here is an example to copy file from \/home\/ubuntu\/data.txt to \/home\/ubuntu\/project.txt.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">shutil.copyfile('\/home\/ubuntu\/data.txt', '\/home\/ubuntu\/project.txt')<\/pre>\n\n\n\n<p>As the name suggests, it can be used to copy files only. It does not support copying of directories.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Using_shutilcopy_function\"><\/span>Using shutil.copy function<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>shutil.copy() function will allow you to easily copy files as well as directories. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">shutil.copy(source, destination, *, follow_symlinks=True)<\/pre>\n\n\n\n<p>The first argument is the path of source file to be copied. The second argument is a path to file or folder. If it is a path to a directory, then the file is copied to this directory using the same file name as that of source file. If it is a file path that exists, then the destination file is overwritten with the file content of source file. Otherwise, it will create a new file as per the destination file path.<\/p>\n\n\n\n<p>The copy() function copies file&#8217;s data and permissions. It does not copy file&#8217;s metadata such as creation date &amp; modification date. If follow_symlinks is set to false, it will create destination as a symbolic link. If it is true, then destination will be a copy of the source.<\/p>\n\n\n\n<p>Here is an example to copy file using this command.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">shutil.copy('\/home\/ubuntu\/data.txt','\/home\/ubuntu\/project.txt')<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Using_shutilcopy2_function\"><\/span>Using shutil.copy2 function<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The shutil.copy2() function works exactly like shutil.copy() function but it also copies the file metadata. So the destination file will have the same creation and modified date as the source file.<\/p>\n\n\n\n<p>Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">shutil.copy(source, destination, *, follow_symlinks=True)<\/pre>\n\n\n\n<p>In this case, if follow_symlinks is false, and the source file is a symlink then the copy2() function will try to copy the source file metadata to destination symlink. But this feature is not available on all platforms. It will do its best to copy as much metadata as possible on the platform. If this is not supported, then it will copy file contents and leave it at that, without raising an Exception.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Using_shutilcopyfileobj\"><\/span>Using shutil.copyfileobj<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>shutil.copyfileobj() function is also useful for copying files. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">shutil.copyfileobj(source, destination [, length])<\/pre>\n\n\n\n<p>In the above code, the first two arguments are for the source and destination file objects. The next argument is for the buffer length, for chunking. It allows you to copy file contents without overloading memory. Here is an example to copy file using this function.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">shutil.copyfileobj('\/home\/ubuntu\/data.txt', '\/home\/ubuntu\/project.txt')<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Using_OS_Module\"><\/span>2. Using OS Module<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>OS module is a very comprehensive module that acts as an interface between Python and underlying OS. It provides tons of functions to easily interact with OS from any Python script, application or websites. It also provides a couple of functions to <a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/\">run system commands from within Python<\/a>. They can be used for copying files using cp or mv function.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Using_ospopen_function\"><\/span>Using os.popen function<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>os.popen() function is a modern function that allows you to easily run system commands and capture their results. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">os.popen(cmd[, mode[, bufsize]])<\/pre>\n\n\n\n<p>Here is an example to copy file from \/home\/ubuntu\/data.txt to \/home\/ubuntu\/project.txt.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">## On Linux<br>os.popen('cp \/home\/ubuntu\/data.txt \/home\/ubuntu\/project.txt') <br><br>## On Windows<br>os.popen('copy \/home\/ubuntu\/data.txt \/home\/ubuntu\/project.txt') <br><\/pre>\n\n\n\n<p>Popen() function allows you to interact with standard input, output and errors. It also creates a new process to run the command and returns a handle that allows you to control the process as per your requirement. It is very useful to easily run cp and mv commands, since they allow you to quickly copy one or more files and directories from one location to another.<\/p>\n\n\n\n<p>Here is an example to copy all files in \/home\/ubuntu to \/home\/projects folder.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">## On Linux<br>os.popen('cp \/home\/ubuntu\/* \/home\/projects') <br><br>## On Windows<br>os.popen('copy \/home\/ubuntu\/* \/home\/projects') <\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Using_ossystem_function\"><\/span>Using os.system function<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>os.system() function allows you to run shell commands within a subshell. If the command returns any output it is sent to standard output. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">os.system(command)<\/pre>\n\n\n\n<p>Here is an example to copy file using os.system() function.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">os.system('cp \/home\/ubuntu\/data.txt \/home\/ubuntu\/project.txt')<\/pre>\n\n\n\n<p>It is not as sophisticated as popen() function but does the work. In fact, popen() function is built on os.system() function.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Using_Subprocess_Module\"><\/span>3. Using Subprocess Module<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Subprocess is a powerful module that allows you to create and control system processes from within Python. You can also use it to connect to input\/output\/error pipes, and obtain return codes. It provides tons of functions for this purpose. You can also use this for running cp command.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Using_subprocesscall\"><\/span>Using subprocess.call<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>subprocess.call() function allows you to run system commands as arguments. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">subprocess.call(args, *, stdin=None, stdout=None, stderr=None, shell=False)<\/pre>\n\n\n\n<p>The above command will run the system command mentioned in args, and return the returncode attribute. If you set shell=True, then it will spawn a new shell for the command. But please note, using shell=True can be a security risk and must be used only if necessary.<\/p>\n\n\n\n<p>Here is an example to run cp command using call() function.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">status = subprocess.call('cp \/home\/ubuntu\/data.txt \/home\/project\/data.txt', shell=True) <\/pre>\n\n\n\n<p>In the above case, we have passed the command as a single string. You can also pass a list of strings for this purpose, as shown below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">status = subprocess.call(['cp', '\/home\/ubuntu\/data.txt', '\/home\/project\/data.txt'], shell=True) <\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Using_subprocesscheck_output\"><\/span>Using subprocess.check_output<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>subprocess.check_output() is another function that runs a command and returns the output, like call function. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">subprocess.check_output(args, *, stdin=None, stderr=None, shell=False, universal_newlines=False)<\/pre>\n\n\n\n<p>Here are the commands to copy files from one location to another.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">## Linux\/Unix<br>status = subprocess.check_output('cp \/home\/ubuntu\/data.txt \/home\/ubuntu\/project.txt', shell=True)<br><br>## Windows<br>status = subprocess.check_output('copy \/home\/ubuntu\/data.txt \/home\/ubuntu\/project.txt', shell=True)<\/pre>\n\n\n\n<p>Like in case of subprocess.call() function, you can pass the command argument as a string or as a list of strings.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># Linux\/Unix<br>status = subprocess.check_output(['cp', '\/home\/ubuntu\/data.txt', '\/home\/ubuntu\/project.txt'], shell=True)<br><br># Windows<br>status = subprocess.check_output(['copy', '\/home\/ubuntu\/data.txt', '\/home\/ubuntu\/project.txt'], shell=True)<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this article, we have learnt several simple ways to easily copy files and directories in Python. You can call these functions from a script, application or website. You can use them to copy a single file, multiple files or an entire directory from one place to another. Please make sure that the source <a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-file-exists-in-python\/\">file actually exists<\/a>. Also ensure that the user that you are using has adequate read permission for source directory, and write permission in destination directory. You can use any of these functions as per your requirement.<\/p>\n\n\n\n<p>Also read:<\/p>\n\n\n\n<p><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-iterate-over-rows-in-pandas-dataframe\/\">How to Iterate Over Rows in Pandas DataFrame<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-iterate-over-dictionaries-using-for-loops\/\">How to Iterate Over Dictionaries Using Loop<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-find-index-of-given-item-in-list-in-python\/\">How to Find Index Of Given Item in Python List<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Often Python developers need to copy files in Python. Here are the different ways to copy files in Python.<\/p>\n","protected":false},"author":1,"featured_media":6786,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[301],"tags":[377],"class_list":["post-6741","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-copy-files"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Copy Files in Python - Ubiq BI<\/title>\n<meta name=\"description\" content=\"Often Python developers need to copy files in Python. Here are the different ways to copy files in Python.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-copy-files-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Copy Files in Python - Ubiq BI\" \/>\n<meta property=\"og:description\" content=\"Often Python developers need to copy files in Python. Here are the different ways to copy files in Python.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ubiq.co\/tech-blog\/how-to-copy-files-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Ubiq BI\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ubiqbi\" \/>\n<meta property=\"article:published_time\" content=\"2025-01-20T07:09:08+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-20T09:35:49+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/copy-files-python.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"301\" \/>\n\t<meta property=\"og:image:height\" content=\"201\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sreeram Sreenivasan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:site\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sreeram Sreenivasan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-copy-files-in-python\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-copy-files-in-python\\\/\"},\"author\":{\"name\":\"Sreeram Sreenivasan\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"headline\":\"How to Copy Files in Python\",\"datePublished\":\"2025-01-20T07:09:08+00:00\",\"dateModified\":\"2025-01-20T09:35:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-copy-files-in-python\\\/\"},\"wordCount\":1226,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-copy-files-in-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/01\\\/copy-files-python.jpg?fit=301%2C201&ssl=1\",\"keywords\":[\"copy files\"],\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-copy-files-in-python\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-copy-files-in-python\\\/\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-copy-files-in-python\\\/\",\"name\":\"How to Copy Files in Python - Ubiq BI\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-copy-files-in-python\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-copy-files-in-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/01\\\/copy-files-python.jpg?fit=301%2C201&ssl=1\",\"datePublished\":\"2025-01-20T07:09:08+00:00\",\"dateModified\":\"2025-01-20T09:35:49+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"description\":\"Often Python developers need to copy files in Python. Here are the different ways to copy files in Python.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-copy-files-in-python\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-copy-files-in-python\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-copy-files-in-python\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/01\\\/copy-files-python.jpg?fit=301%2C201&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/01\\\/copy-files-python.jpg?fit=301%2C201&ssl=1\",\"width\":301,\"height\":201,\"caption\":\"copy files in python\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-copy-files-in-python\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Copy Files in Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\",\"name\":\"Ubiq BI\",\"description\":\"Build dashboards &amp; reports in minutes\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\",\"name\":\"Sreeram Sreenivasan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"caption\":\"Sreeram Sreenivasan\"},\"description\":\"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/sreeram-sreenivasan\\\/\"],\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/author\\\/wordpress\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Copy Files in Python - Ubiq BI","description":"Often Python developers need to copy files in Python. Here are the different ways to copy files in Python.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/ubiq.co\/tech-blog\/how-to-copy-files-in-python\/","og_locale":"en_US","og_type":"article","og_title":"How to Copy Files in Python - Ubiq BI","og_description":"Often Python developers need to copy files in Python. Here are the different ways to copy files in Python.","og_url":"https:\/\/ubiq.co\/tech-blog\/how-to-copy-files-in-python\/","og_site_name":"Ubiq BI","article_publisher":"https:\/\/www.facebook.com\/ubiqbi","article_published_time":"2025-01-20T07:09:08+00:00","article_modified_time":"2025-01-20T09:35:49+00:00","og_image":[{"width":301,"height":201,"url":"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/copy-files-python.jpg","type":"image\/jpeg"}],"author":"Sreeram Sreenivasan","twitter_card":"summary_large_image","twitter_creator":"@UbiqBI","twitter_site":"@UbiqBI","twitter_misc":{"Written by":"Sreeram Sreenivasan","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-copy-files-in-python\/#article","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-copy-files-in-python\/"},"author":{"name":"Sreeram Sreenivasan","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"headline":"How to Copy Files in Python","datePublished":"2025-01-20T07:09:08+00:00","dateModified":"2025-01-20T09:35:49+00:00","mainEntityOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-copy-files-in-python\/"},"wordCount":1226,"commentCount":0,"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-copy-files-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/copy-files-python.jpg?fit=301%2C201&ssl=1","keywords":["copy files"],"articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ubiq.co\/tech-blog\/how-to-copy-files-in-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-copy-files-in-python\/","url":"https:\/\/ubiq.co\/tech-blog\/how-to-copy-files-in-python\/","name":"How to Copy Files in Python - Ubiq BI","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-copy-files-in-python\/#primaryimage"},"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-copy-files-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/copy-files-python.jpg?fit=301%2C201&ssl=1","datePublished":"2025-01-20T07:09:08+00:00","dateModified":"2025-01-20T09:35:49+00:00","author":{"@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"description":"Often Python developers need to copy files in Python. Here are the different ways to copy files in Python.","breadcrumb":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-copy-files-in-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ubiq.co\/tech-blog\/how-to-copy-files-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-copy-files-in-python\/#primaryimage","url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/copy-files-python.jpg?fit=301%2C201&ssl=1","contentUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/copy-files-python.jpg?fit=301%2C201&ssl=1","width":301,"height":201,"caption":"copy files in python"},{"@type":"BreadcrumbList","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-copy-files-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ubiq.co\/tech-blog\/"},{"@type":"ListItem","position":2,"name":"How to Copy Files in Python"}]},{"@type":"WebSite","@id":"https:\/\/ubiq.co\/tech-blog\/#website","url":"https:\/\/ubiq.co\/tech-blog\/","name":"Ubiq BI","description":"Build dashboards &amp; reports in minutes","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ubiq.co\/tech-blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc","name":"Sreeram Sreenivasan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","caption":"Sreeram Sreenivasan"},"description":"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.","sameAs":["https:\/\/www.linkedin.com\/in\/sreeram-sreenivasan\/"],"url":"https:\/\/ubiq.co\/tech-blog\/author\/wordpress\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/copy-files-python.jpg?fit=301%2C201&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pbGGTT-1KJ","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/6741","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/comments?post=6741"}],"version-history":[{"count":51,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/6741\/revisions"}],"predecessor-version":[{"id":6797,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/6741\/revisions\/6797"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media\/6786"}],"wp:attachment":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media?parent=6741"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/categories?post=6741"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/tags?post=6741"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}