{"id":7900,"date":"2012-09-21T19:43:31","date_gmt":"2012-09-21T14:13:31","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=7900"},"modified":"2016-11-29T16:44:36","modified_gmt":"2016-11-29T11:14:36","slug":"copy-filesfolders-from-one-location-to-another-in-groovy","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/copy-filesfolders-from-one-location-to-another-in-groovy\/","title":{"rendered":"Copy Files\/Folders from one location to another in Groovy"},"content":{"rendered":"<p>It is normally difficult to copy file\/folders from one location to another. In my recent <a title=\"Grails Development\" href=\"http:\/\/www.tothenew.com\/grails-application-development\" target=\"_blank\">Grails Development<\/a>\u00a0project, i successfully achieved this. I had to copy files\/folders from one location to another on file system. I searched about it and came across a cool method to copy files or directories from one location to another.<\/p>\n<p>We can simply copy files, directories, exclude particular files as we have good control in it. Below is the code which explains how to use it.<\/p>\n<p><strong>Copy directory to another directory :-<\/strong><\/p>\n<p>[java]<\/p>\n<p>        String sourceDir = SOURCE_DIR_PATH<br \/>\n        String destinationDir = DESTINATION_DIR_PATH<br \/>\n        new AntBuilder().copy(todir: destinationDir) {<br \/>\n            fileset(dir: sourceDir)<br \/>\n        }<\/p>\n<p>[\/java]<\/p>\n<p>This method will copy the source directory to the destination directory with all the internal data in the same structure.<\/p>\n<p>Suppose if we want to exclude some particular file(s), then we can easily provide that file name or the common pattern of those files as mentioned in the example.<\/p>\n<p><strong>Copy directory with excluding some files :-<\/strong><\/p>\n<p>[java]<br \/>\n      String sourceDir = SOURCE_DIR_PATH<br \/>\n      String destinationDir = DESTINATION_DIR_PATH<\/p>\n<p>      new AntBuilder().copy(todir: destinationDir) {<br \/>\n           fileset(dir : sourceDir) {<br \/>\n                 exclude(name:&quot;*.java&quot;)<br \/>\n      }<br \/>\n   }<\/p>\n<p>[\/java]<\/p>\n<p>The above code will not copy the files which have an extension <strong>.java<\/strong><\/p>\n<p>Now if i want to copy any particular file, then there is other method to copy it as given below.<\/p>\n<p><strong>Copy files from one directory to another :-<\/strong><\/p>\n<p>[java]<\/p>\n<p>        String sourceFilePath = SOURCE_FILE_PATH<br \/>\n         String destinationFilePath = DESTINATION_FILE_PATH<br \/>\n         (new AntBuilder()).copy(file: sourceFilePath, tofile: destinationFilePath)<\/p>\n<p>[\/java]<\/p>\n<p>This method will copy the provided file to the destination location.<\/p>\n<p>This worked for me. Hope it helps.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It is normally difficult to copy file\/folders from one location to another. In my recent Grails Development\u00a0project, i successfully achieved this. I had to copy files\/folders from one location to another on file system. I searched about it and came across a cool method to copy files or directories from one location to another. We [&hellip;]<\/p>\n","protected":false},"author":19,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":326,"footnotes":""},"categories":[7,3917,1994],"tags":[4840,9],"class_list":["post-7900","post","type-post","status-publish","format-standard","hentry","category-grails","category-product-engineering-2","category-software-development","tag-grails","tag-groovy"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"In this blog, we shall walk you through a cool method for copying file\/folder from one location to another in Grails.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Vishal Sahu\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.tothenew.com\/blog\/copy-filesfolders-from-one-location-to-another-in-groovy\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"TO THE NEW BLOG\" \/>\n\t\t<meta property=\"og:type\" content=\"blog\" \/>\n\t\t<meta property=\"og:title\" content=\"Copying file or folder in Grails Development project | TO THE NEW Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"In this blog, we shall walk you through a cool method for copying file\/folder from one location to another in Grails.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.tothenew.com\/blog\/copy-filesfolders-from-one-location-to-another-in-groovy\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@tothenew\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Copying file or folder in Grails Development project | TO THE NEW Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"In this blog, we shall walk you through a cool method for copying file\/folder from one location to another in Grails.\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/copy-filesfolders-from-one-location-to-another-in-groovy\\\/#article\",\"name\":\"Copying file or folder in Grails Development project | TO THE NEW Blog\",\"headline\":\"Copy Files\\\/Folders from one location to another in Groovy\",\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/vishal\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"},\"datePublished\":\"2012-09-21T19:43:31+05:30\",\"dateModified\":\"2016-11-29T16:44:36+05:30\",\"inLanguage\":\"en-US\",\"commentCount\":5,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/copy-filesfolders-from-one-location-to-another-in-groovy\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/copy-filesfolders-from-one-location-to-another-in-groovy\\\/#webpage\"},\"articleSection\":\"Grails, Product Engineering, Software development, Grails, Groovy\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/copy-filesfolders-from-one-location-to-another-in-groovy\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/#listItem\",\"name\":\"Grails\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/#listItem\",\"position\":2,\"name\":\"Grails\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/copy-filesfolders-from-one-location-to-another-in-groovy\\\/#listItem\",\"name\":\"Copy Files\\\/Folders from one location to another in Groovy\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/copy-filesfolders-from-one-location-to-another-in-groovy\\\/#listItem\",\"position\":3,\"name\":\"Copy Files\\\/Folders from one location to another in Groovy\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/#listItem\",\"name\":\"Grails\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\",\"name\":\"TO THE NEW Blog\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/vishal\\\/#author\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/vishal\\\/\",\"name\":\"Vishal Sahu\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/copy-filesfolders-from-one-location-to-another-in-groovy\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/04ab2997182dff5e957d14b30bdc77fc09933e3d6e7f97b00f8ee27b193602a2?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Vishal Sahu\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/copy-filesfolders-from-one-location-to-another-in-groovy\\\/#webpage\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/copy-filesfolders-from-one-location-to-another-in-groovy\\\/\",\"name\":\"Copying file or folder in Grails Development project | TO THE NEW Blog\",\"description\":\"In this blog, we shall walk you through a cool method for copying file\\\/folder from one location to another in Grails.\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/copy-filesfolders-from-one-location-to-another-in-groovy\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/vishal\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/vishal\\\/#author\"},\"datePublished\":\"2012-09-21T19:43:31+05:30\",\"dateModified\":\"2016-11-29T16:44:36+05:30\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\",\"name\":\"TO THE NEW Blog\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Copying file or folder in Grails Development project | TO THE NEW Blog","description":"In this blog, we shall walk you through a cool method for copying file\/folder from one location to another in Grails.","canonical_url":"https:\/\/www.tothenew.com\/blog\/copy-filesfolders-from-one-location-to-another-in-groovy\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.tothenew.com\/blog\/copy-filesfolders-from-one-location-to-another-in-groovy\/#article","name":"Copying file or folder in Grails Development project | TO THE NEW Blog","headline":"Copy Files\/Folders from one location to another in Groovy","author":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/vishal\/#author"},"publisher":{"@id":"https:\/\/www.tothenew.com\/blog\/#organization"},"datePublished":"2012-09-21T19:43:31+05:30","dateModified":"2016-11-29T16:44:36+05:30","inLanguage":"en-US","commentCount":5,"mainEntityOfPage":{"@id":"https:\/\/www.tothenew.com\/blog\/copy-filesfolders-from-one-location-to-another-in-groovy\/#webpage"},"isPartOf":{"@id":"https:\/\/www.tothenew.com\/blog\/copy-filesfolders-from-one-location-to-another-in-groovy\/#webpage"},"articleSection":"Grails, Product Engineering, Software development, Grails, Groovy"},{"@type":"BreadcrumbList","@id":"https:\/\/www.tothenew.com\/blog\/copy-filesfolders-from-one-location-to-another-in-groovy\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/www.tothenew.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/grails\/#listItem","name":"Grails"}},{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/grails\/#listItem","position":2,"name":"Grails","item":"https:\/\/www.tothenew.com\/blog\/category\/grails\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/copy-filesfolders-from-one-location-to-another-in-groovy\/#listItem","name":"Copy Files\/Folders from one location to another in Groovy"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/copy-filesfolders-from-one-location-to-another-in-groovy\/#listItem","position":3,"name":"Copy Files\/Folders from one location to another in Groovy","previousItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/grails\/#listItem","name":"Grails"}}]},{"@type":"Organization","@id":"https:\/\/www.tothenew.com\/blog\/#organization","name":"TO THE NEW Blog","url":"https:\/\/www.tothenew.com\/blog\/"},{"@type":"Person","@id":"https:\/\/www.tothenew.com\/blog\/author\/vishal\/#author","url":"https:\/\/www.tothenew.com\/blog\/author\/vishal\/","name":"Vishal Sahu","image":{"@type":"ImageObject","@id":"https:\/\/www.tothenew.com\/blog\/copy-filesfolders-from-one-location-to-another-in-groovy\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/04ab2997182dff5e957d14b30bdc77fc09933e3d6e7f97b00f8ee27b193602a2?s=96&d=mm&r=g","width":96,"height":96,"caption":"Vishal Sahu"}},{"@type":"WebPage","@id":"https:\/\/www.tothenew.com\/blog\/copy-filesfolders-from-one-location-to-another-in-groovy\/#webpage","url":"https:\/\/www.tothenew.com\/blog\/copy-filesfolders-from-one-location-to-another-in-groovy\/","name":"Copying file or folder in Grails Development project | TO THE NEW Blog","description":"In this blog, we shall walk you through a cool method for copying file\/folder from one location to another in Grails.","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.tothenew.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/www.tothenew.com\/blog\/copy-filesfolders-from-one-location-to-another-in-groovy\/#breadcrumblist"},"author":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/vishal\/#author"},"creator":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/vishal\/#author"},"datePublished":"2012-09-21T19:43:31+05:30","dateModified":"2016-11-29T16:44:36+05:30"},{"@type":"WebSite","@id":"https:\/\/www.tothenew.com\/blog\/#website","url":"https:\/\/www.tothenew.com\/blog\/","name":"TO THE NEW Blog","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.tothenew.com\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"TO THE NEW BLOG","og:type":"blog","og:title":"Copying file or folder in Grails Development project | TO THE NEW Blog","og:description":"In this blog, we shall walk you through a cool method for copying file\/folder from one location to another in Grails.","og:url":"https:\/\/www.tothenew.com\/blog\/copy-filesfolders-from-one-location-to-another-in-groovy\/","og:image":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","og:image:secure_url":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","twitter:card":"summary","twitter:site":"@tothenew","twitter:title":"Copying file or folder in Grails Development project | TO THE NEW Blog","twitter:description":"In this blog, we shall walk you through a cool method for copying file\/folder from one location to another in Grails.","twitter:image":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png"},"aioseo_meta_data":{"post_id":"7900","title":"Copying file or folder in Grails Development project | #site_title","description":"In this blog, we shall walk you through a cool method for copying file\/folder from one location to another in Grails.","keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":"","og_description":"","og_object_type":"blog","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":"","og_article_tags":"","twitter_use_og":false,"twitter_card":"summary","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"created":"2021-04-29 13:45:23","updated":"2024-02-29 08:18:37","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tothenew.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tothenew.com\/blog\/category\/grails\/\" title=\"Grails\">Grails<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tCopy Files\/Folders from one location to another in Groovy\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.tothenew.com\/blog"},{"label":"Grails","link":"https:\/\/www.tothenew.com\/blog\/category\/grails\/"},{"label":"Copy Files\/Folders from one location to another in Groovy","link":"https:\/\/www.tothenew.com\/blog\/copy-filesfolders-from-one-location-to-another-in-groovy\/"}],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/7900","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=7900"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/7900\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=7900"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=7900"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=7900"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}