{"id":39190,"date":"2025-11-07T15:14:19","date_gmt":"2025-11-07T23:14:19","guid":{"rendered":"https:\/\/cloudinary.com\/blog\/?p=39190"},"modified":"2025-11-07T15:14:19","modified_gmt":"2025-11-07T23:14:19","slug":"how-to-copy-a-file-in-python","status":"publish","type":"post","link":"https:\/\/cloudinary.com\/blog\/questions\/how-to-copy-a-file-in-python\/","title":{"rendered":"How to copy a file in Python?"},"content":{"rendered":"\n<p>You are iterating quickly on a project and want a clean, reliable way to duplicate files or whole folders as part of your build or backup script. Here&#8217;s a common question developers pose, along with a ready-to-use answer for your code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Question:<\/h2>\n\n\n\n<p><em>How to copy a file in Python so that it works on Windows, macOS, and Linux? I need to handle both single files and entire directories, preserve timestamps and permissions where possible, avoid accidental overwrites, and keep performance in mind for large files. What are the right functions from the standard library, any pitfalls to watch for, and can you share some minimal examples?<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Answer:<\/h2>\n\n\n\n<p>Python\u2019s standard library provides everything you need for robust file and directory copying. The shutil and pathlib modules cover most use cases, and they keep your code portable across platforms.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Pick the right function<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>shutil.copy(src, dst): Copies file data and permission bits.<\/li>\n\n\n\n<li>shutil.copy2(src, dst): Like copy, plus attempts to preserve metadata such as timestamps.<\/li>\n\n\n\n<li>shutil.copyfile(src, dst): Copies file data only. Fast, but does not preserve permissions or metadata.<\/li>\n\n\n\n<li>shutil.copytree(src, dst, &#8230;): Recursively copies directories.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Basic examples<\/h3>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php shcb-wrap-lines\"><span class=\"hljs-comment\"># 1) Copy a single file and preserve metadata<\/span>\nfrom pathlib import Path\nimport shutil\n\nsrc = Path(<span class=\"hljs-string\">\"data\/report.csv\"<\/span>)\ndst = Path(<span class=\"hljs-string\">\"backup\/report.csv\"<\/span>)\ndst.<span class=\"hljs-keyword\">parent<\/span>.mkdir(parents=<span class=\"hljs-keyword\">True<\/span>, exist_ok=<span class=\"hljs-keyword\">True<\/span>)\u00a0 <span class=\"hljs-comment\"># ensure destination folder exists<\/span>\nshutil.copy2(src, dst)\u00a0 <span class=\"hljs-comment\"># preserves timestamps where supported<\/span>\n\n<span class=\"hljs-comment\"># 2) Copy a file without overwriting accidentally<\/span>\nfrom pathlib import Path\nimport shutil\n\nsrc = Path(<span class=\"hljs-string\">\"data\/report.csv\"<\/span>)\ndst = Path(<span class=\"hljs-string\">\"backup\/report.csv\"<\/span>)\n\n<span class=\"hljs-keyword\">if<\/span> dst.exists():\n\u00a0 \u00a0 raise FileExistsError(f<span class=\"hljs-string\">\"{dst} already exists\"<\/span>)\nshutil.copy2(src, dst)\n\n<span class=\"hljs-comment\"># 3) Copy an entire directory tree (Python 3.8+)<\/span>\nimport shutil\n\nshutil.copytree(<span class=\"hljs-string\">\"assets\"<\/span>, <span class=\"hljs-string\">\"backup\/assets\"<\/span>, dirs_exist_ok=<span class=\"hljs-keyword\">True<\/span>)\n<span class=\"hljs-comment\"># Ignore patterns (e.g., .git and *.tmp):<\/span>\n<span class=\"hljs-comment\"># shutil.copytree(\"assets\", \"backup\/assets\", dirs_exist_ok=True,<\/span>\n<span class=\"hljs-comment\"># \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 ignore=shutil.ignore_patterns(\".git\", \"*.tmp\"))<\/span>\n\n<span class=\"hljs-comment\"># 4) Efficient copy for large files using a buffer<\/span>\nimport shutil\n\nwith open(<span class=\"hljs-string\">\"big.iso\"<\/span>, <span class=\"hljs-string\">\"rb\"<\/span>) <span class=\"hljs-keyword\">as<\/span> fsrc, open(<span class=\"hljs-string\">\"backup\/big.iso\"<\/span>, <span class=\"hljs-string\">\"wb\"<\/span>) <span class=\"hljs-keyword\">as<\/span> fdst:\n\u00a0 \u00a0 shutil.copyfileobj(fsrc, fdst, length=<span class=\"hljs-number\">1024<\/span> * <span class=\"hljs-number\">1024<\/span>)\u00a0 <span class=\"hljs-comment\"># 1 MB chunks<\/span>\n\n<span class=\"hljs-comment\"># 5) Atomic-like replace to avoid partial files on failures<\/span>\nfrom pathlib import Path\nimport shutil\n\nsrc = Path(<span class=\"hljs-string\">\"data\/report.csv\"<\/span>)\ndst = Path(<span class=\"hljs-string\">\"backup\/report.csv\"<\/span>)\ntmp = dst.with_suffix(dst.suffix + <span class=\"hljs-string\">\".tmp\"<\/span>)\n\nshutil.copy2(src, tmp)\ntmp.replace(dst)\u00a0 <span class=\"hljs-comment\"># os.replace under the hood; atomic on many filesystems<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">When to use which<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Use shutil.copy2 <\/strong>for backups where you care about timestamps and permissions.<\/li>\n\n\n\n<li><strong>Use shutil.copyfile<\/strong> when you need speed and do not care about metadata.<\/li>\n\n\n\n<li><strong>Use shutil.copytree <\/strong>for directories, optionally with ignore patterns and symlink handling (symlinks=True).<\/li>\n\n\n\n<li><strong>Use pathlib.Path <\/strong>for safe, cross-platform path handling.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Common pitfalls and tips<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Cross-platform paths:<\/strong> Always build paths with pathlib instead of string concatenation.<\/li>\n\n\n\n<li><strong>Permissions: <\/strong>Metadata preservation varies by OS and filesystem; copy2 does its best but is not guaranteed on all platforms.<\/li>\n\n\n\n<li><strong>Existing targets: <\/strong>Decide whether to overwrite or fail fast. copyfile and copy2 will overwrite by default.<\/li>\n\n\n\n<li><strong>Concurrency: <\/strong>For multi-process copy flows, use a temp file then replace to avoid readers seeing partial content.<\/li>\n\n\n\n<li><strong>Very large folders:<\/strong> Consider filtering with ignore_patterns to skip unnecessary files.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Optional: managing media without duplicating files<\/h3>\n\n\n\n<p>If you are copying images or videos mainly to create resized or reformatted variants, a media platform can help avoid local duplication altogether. For example, you can upload a master asset once, then deliver many variants from a single canonical source using transformation parameters in the asset URL.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php shcb-wrap-lines\"><span class=\"hljs-comment\"># Example: upload once, then deliver variants via URL without making file copies<\/span>\n\nimport cloudinary\nimport cloudinary.uploader\n\ncloudinary.config(\n\u00a0 \u00a0 cloud_name=<span class=\"hljs-string\">\"demo\"<\/span>,\n\u00a0 \u00a0 api_key=<span class=\"hljs-string\">\"1234567890\"<\/span>,\n\u00a0 \u00a0 api_secret=<span class=\"hljs-string\">\"a_very_secret_key\"<\/span>,\n\u00a0 \u00a0 secure=<span class=\"hljs-keyword\">True<\/span>\n)\n\n<span class=\"hljs-comment\"># Upload original<\/span>\n\nres = cloudinary.uploader.upload(\n\u00a0 \u00a0 <span class=\"hljs-string\">\"assets\/photo.jpg\"<\/span>,\n\u00a0 \u00a0 folder=<span class=\"hljs-string\">\"backups\"<\/span>,\n\u00a0 \u00a0 public_id=<span class=\"hljs-string\">\"photo-v1\"<\/span>,\n\u00a0 \u00a0 overwrite=<span class=\"hljs-keyword\">False<\/span>\n)\n\n<span class=\"hljs-comment\"># Later, request a resized or compressed variant by URL (no new file needed): <\/span>\n\nhttps:<span class=\"hljs-comment\">\/\/res.cloudinary.com\/\/image\/upload\/f_auto,q_auto,w_1024\/backups\/photo-v1.jpg<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This pattern reduces storage and I\/O, centralizes asset management, and helps enforce a consistent <a href=\"https:\/\/cloudinary.com\/glossary\/file-management-system\">file management system<\/a>. Since variants are created on the fly using transformation parameters, the <a href=\"https:\/\/cloudinary.com\/glossary\/image-url\">image URL<\/a> itself becomes the API for delivery.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">TL;DR<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use shutil.copy2 for copying single files with metadata, and shutil.copytree for directories.<\/li>\n\n\n\n<li>Guard against accidental overwrites and prefer atomic replace patterns for reliability.<\/li>\n\n\n\n<li>Pathlib keeps your paths portable and readable.<\/li>\n\n\n\n<li>For media, upload once and generate variants via URL to avoid local file copies and save storage.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Learn More<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/cloudinary.com\/tools\/image-to-jpg\">Image to JPG<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/cloudinary.com\/tools\/png-to-webp\">PNG to WebP<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/cloudinary.com\/tools\/image-to-link\">Image to Link<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/cloudinary.com\/guides\/digital-asset-management\/digital-asset-management\">Digital Asset Management Guide<\/a><\/li>\n<\/ul>\n\n\n\n<p>Ready to streamline how you store, transform, and deliver media while keeping your Python code simple? <a href=\"https:\/\/cloudinary.com\/users\/register_free\">Create a free Cloudinary account<\/a> and start optimizing your workflow today.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You are iterating quickly on a project and want a clean, reliable way to duplicate files or whole folders as part of your build or backup script. Here&#8217;s a common question developers pose, along with a ready-to-use answer for your code. Question: How to copy a file in Python so that it works on Windows, [&hellip;]<\/p>\n","protected":false},"author":88,"featured_media":39191,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_cloudinary_featured_overwrite":false,"footnotes":""},"categories":[1],"tags":[423],"class_list":["post-39190","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-questions"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.6 (Yoast SEO v26.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to copy a file in Python?<\/title>\n<meta name=\"description\" content=\"You are iterating quickly on a project and want a clean, reliable way to duplicate files or whole folders as part of your build or backup script. Here&#039;s a\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cloudinary.com\/blog\/questions\/how-to-copy-a-file-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 a file in Python?\" \/>\n<meta property=\"og:description\" content=\"You are iterating quickly on a project and want a clean, reliable way to duplicate files or whole folders as part of your build or backup script. Here&#039;s a\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cloudinary.com\/blog\/questions\/how-to-copy-a-file-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Cloudinary Blog\" \/>\n<meta property=\"article:published_time\" content=\"2025-11-07T23:14:19+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762557227\/how_to_copy_a_file_in_python_featured_image\/how_to_copy_a_file_in_python_featured_image.jpg?_i=AA\" \/>\n\t<meta property=\"og:image:width\" content=\"2000\" \/>\n\t<meta property=\"og:image:height\" content=\"1100\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"damjanantevski\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"NewsArticle\",\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/how-to-copy-a-file-in-python\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/how-to-copy-a-file-in-python\/\"},\"author\":{\"name\":\"damjanantevski\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/43592e43c12520a1e867d456b1e8cf7e\"},\"headline\":\"How to copy a file in Python?\",\"datePublished\":\"2025-11-07T23:14:19+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/how-to-copy-a-file-in-python\/\"},\"wordCount\":513,\"publisher\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/how-to-copy-a-file-in-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762557227\/how_to_copy_a_file_in_python_featured_image\/how_to_copy_a_file_in_python_featured_image.jpg?_i=AA\",\"keywords\":[\"Questions\"],\"inLanguage\":\"en-US\",\"copyrightYear\":\"2025\",\"copyrightHolder\":{\"@id\":\"https:\/\/cloudinary.com\/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/how-to-copy-a-file-in-python\/\",\"url\":\"https:\/\/cloudinary.com\/blog\/questions\/how-to-copy-a-file-in-python\/\",\"name\":\"How to copy a file in Python?\",\"isPartOf\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/how-to-copy-a-file-in-python\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/how-to-copy-a-file-in-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762557227\/how_to_copy_a_file_in_python_featured_image\/how_to_copy_a_file_in_python_featured_image.jpg?_i=AA\",\"datePublished\":\"2025-11-07T23:14:19+00:00\",\"description\":\"You are iterating quickly on a project and want a clean, reliable way to duplicate files or whole folders as part of your build or backup script. Here's a\",\"breadcrumb\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/how-to-copy-a-file-in-python\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cloudinary.com\/blog\/questions\/how-to-copy-a-file-in-python\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/how-to-copy-a-file-in-python\/#primaryimage\",\"url\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762557227\/how_to_copy_a_file_in_python_featured_image\/how_to_copy_a_file_in_python_featured_image.jpg?_i=AA\",\"contentUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762557227\/how_to_copy_a_file_in_python_featured_image\/how_to_copy_a_file_in_python_featured_image.jpg?_i=AA\",\"width\":2000,\"height\":1100},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/how-to-copy-a-file-in-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/cloudinary.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to copy a file in Python?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#website\",\"url\":\"https:\/\/cloudinary.com\/blog\/\",\"name\":\"Cloudinary Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/cloudinary.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#organization\",\"name\":\"Cloudinary Blog\",\"url\":\"https:\/\/cloudinary.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA\",\"contentUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA\",\"width\":312,\"height\":60,\"caption\":\"Cloudinary Blog\"},\"image\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/43592e43c12520a1e867d456b1e8cf7e\",\"name\":\"damjanantevski\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/3b40c995531fe4d510212a06c9d4fc666d2cb8efbfebc98a94191701accf4817?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/3b40c995531fe4d510212a06c9d4fc666d2cb8efbfebc98a94191701accf4817?s=96&d=mm&r=g\",\"caption\":\"damjanantevski\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to copy a file in Python?","description":"You are iterating quickly on a project and want a clean, reliable way to duplicate files or whole folders as part of your build or backup script. Here's a","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:\/\/cloudinary.com\/blog\/questions\/how-to-copy-a-file-in-python\/","og_locale":"en_US","og_type":"article","og_title":"How to copy a file in Python?","og_description":"You are iterating quickly on a project and want a clean, reliable way to duplicate files or whole folders as part of your build or backup script. Here's a","og_url":"https:\/\/cloudinary.com\/blog\/questions\/how-to-copy-a-file-in-python\/","og_site_name":"Cloudinary Blog","article_published_time":"2025-11-07T23:14:19+00:00","og_image":[{"width":2000,"height":1100,"url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762557227\/how_to_copy_a_file_in_python_featured_image\/how_to_copy_a_file_in_python_featured_image.jpg?_i=AA","type":"image\/jpeg"}],"author":"damjanantevski","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-copy-a-file-in-python\/#article","isPartOf":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-copy-a-file-in-python\/"},"author":{"name":"damjanantevski","@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/43592e43c12520a1e867d456b1e8cf7e"},"headline":"How to copy a file in Python?","datePublished":"2025-11-07T23:14:19+00:00","mainEntityOfPage":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-copy-a-file-in-python\/"},"wordCount":513,"publisher":{"@id":"https:\/\/cloudinary.com\/blog\/#organization"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-copy-a-file-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762557227\/how_to_copy_a_file_in_python_featured_image\/how_to_copy_a_file_in_python_featured_image.jpg?_i=AA","keywords":["Questions"],"inLanguage":"en-US","copyrightYear":"2025","copyrightHolder":{"@id":"https:\/\/cloudinary.com\/#organization"}},{"@type":"WebPage","@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-copy-a-file-in-python\/","url":"https:\/\/cloudinary.com\/blog\/questions\/how-to-copy-a-file-in-python\/","name":"How to copy a file in Python?","isPartOf":{"@id":"https:\/\/cloudinary.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-copy-a-file-in-python\/#primaryimage"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-copy-a-file-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762557227\/how_to_copy_a_file_in_python_featured_image\/how_to_copy_a_file_in_python_featured_image.jpg?_i=AA","datePublished":"2025-11-07T23:14:19+00:00","description":"You are iterating quickly on a project and want a clean, reliable way to duplicate files or whole folders as part of your build or backup script. Here's a","breadcrumb":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-copy-a-file-in-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cloudinary.com\/blog\/questions\/how-to-copy-a-file-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-copy-a-file-in-python\/#primaryimage","url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762557227\/how_to_copy_a_file_in_python_featured_image\/how_to_copy_a_file_in_python_featured_image.jpg?_i=AA","contentUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762557227\/how_to_copy_a_file_in_python_featured_image\/how_to_copy_a_file_in_python_featured_image.jpg?_i=AA","width":2000,"height":1100},{"@type":"BreadcrumbList","@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-copy-a-file-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cloudinary.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to copy a file in Python?"}]},{"@type":"WebSite","@id":"https:\/\/cloudinary.com\/blog\/#website","url":"https:\/\/cloudinary.com\/blog\/","name":"Cloudinary Blog","description":"","publisher":{"@id":"https:\/\/cloudinary.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cloudinary.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/cloudinary.com\/blog\/#organization","name":"Cloudinary Blog","url":"https:\/\/cloudinary.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA","contentUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA","width":312,"height":60,"caption":"Cloudinary Blog"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/43592e43c12520a1e867d456b1e8cf7e","name":"damjanantevski","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/3b40c995531fe4d510212a06c9d4fc666d2cb8efbfebc98a94191701accf4817?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3b40c995531fe4d510212a06c9d4fc666d2cb8efbfebc98a94191701accf4817?s=96&d=mm&r=g","caption":"damjanantevski"}}]}},"jetpack_featured_media_url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762557227\/how_to_copy_a_file_in_python_featured_image\/how_to_copy_a_file_in_python_featured_image.jpg?_i=AA","_links":{"self":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/39190","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/users\/88"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/comments?post=39190"}],"version-history":[{"count":1,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/39190\/revisions"}],"predecessor-version":[{"id":39192,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/39190\/revisions\/39192"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/media\/39191"}],"wp:attachment":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/media?parent=39190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/categories?post=39190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/tags?post=39190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}