{"id":59067,"date":"2016-09-09T16:21:34","date_gmt":"2016-09-09T16:21:34","guid":{"rendered":"http:\/\/webkul.com\/blog\/?p=59067"},"modified":"2024-03-22T10:07:50","modified_gmt":"2024-03-22T10:07:50","slug":"add-directory-using-setup-script-magento2","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/add-directory-using-setup-script-magento2\/","title":{"rendered":"How to add directory using setup script in Magento2"},"content":{"rendered":"\n<p>How to add directory using setup script in Magento2 :- Here, I am going to show that how to create directory using setup-patch file in <a href=\"https:\/\/store.webkul.com\/Magento-2.html\">magento2<\/a>.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create AddDirectory.php at this path &#8220;Namespace\\ModuleName\\Setup\\Patch\\Data&#8221;<\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\nnamespace Namespace\\ModuleName\\Setup\\Patch\\Data;\n\nuse Magento\\Framework\\Setup\\Patch\\DataPatchInterface;\nuse Magento\\Framework\\Filesystem\\Io\\File;\nuse Magento\\Framework\\App\\Filesystem\\DirectoryList;\n\nclass AddDirectory implements DataPatchInterface\n{\n    \/**\n     * @var File\n     *\/\n    private $io;\n\n    \/**\n     * @var DirectoryList\n     *\/\n    private $directoryList;\n\n    \/**\n     * @param File $io\n     * @param DirectoryList $directoryList\n     *\/\n    public function __construct(\n        File $io,\n        DirectoryList $directoryList\n    ) {\n        $this-&gt;_io = $io;\n        $this-&gt;_directoryList = $directoryList;\n    }\n\n    public function apply()\n    {\n        $this-&gt;_io-&gt;mkdir($this-&gt;_directoryList-&gt;getPath('media').'\/tempFolder', 0755);\n    }\n    \n    \/**\n     * {@inheritdoc}\n     *\/\n    public function getAliases()\n    {\n        return [];\n    }\n\n    \/**\n     * {@inheritdoc}\n     *\/\n    public static function getDependencies()\n    {\n        return [];\n    }\n}\n<\/pre>\n\n\n\n<p>After completing it, When you run upgrade command. This directory will be created at given path.<\/p>\n\n\n\n<p>Thank&#8217;s , Hope so it will help you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to add directory using setup script in Magento2 :- Here, I am going to show that how to create directory using setup-patch file in magento2. After completing it, When you run upgrade command. This directory will be created at given path. Thank&#8217;s , Hope so it will help you.<\/p>\n","protected":false},"author":115,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[302],"tags":[3607,2056,2070,590],"class_list":["post-59067","post","type-post","status-publish","format-standard","hentry","category-magento2","tag-how-to-add-directory-using-setup-script-in-magento2","tag-magento","tag-magento2","tag-webkul"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to add directory using setup script in Magento2<\/title>\n<meta name=\"description\" content=\"How to add directory using setup script in Magento2,using magento2 installer,using setup-script,automatically add folder in at the time of module install\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/add-directory-using-setup-script-magento2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to add directory using setup script in Magento2\" \/>\n<meta property=\"og:description\" content=\"How to add directory using setup script in Magento2,using magento2 installer,using setup-script,automatically add folder in at the time of module install\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/add-directory-using-setup-script-magento2\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2016-09-09T16:21:34+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-22T10:07:50+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Shubham Sharma\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Shubham Sharma\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/add-directory-using-setup-script-magento2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/add-directory-using-setup-script-magento2\/\"},\"author\":{\"name\":\"Shubham Sharma\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/ae41bc19a6783d2f09c6b9b3a0fbddfd\"},\"headline\":\"How to add directory using setup script in Magento2\",\"datePublished\":\"2016-09-09T16:21:34+00:00\",\"dateModified\":\"2024-03-22T10:07:50+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/add-directory-using-setup-script-magento2\/\"},\"wordCount\":69,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"keywords\":[\"How to add directory using setup script in magento2\",\"magento\",\"Magento2\",\"webkul\"],\"articleSection\":[\"Magento2\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/add-directory-using-setup-script-magento2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/add-directory-using-setup-script-magento2\/\",\"url\":\"https:\/\/webkul.com\/blog\/add-directory-using-setup-script-magento2\/\",\"name\":\"How to add directory using setup script in Magento2\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"datePublished\":\"2016-09-09T16:21:34+00:00\",\"dateModified\":\"2024-03-22T10:07:50+00:00\",\"description\":\"How to add directory using setup script in Magento2,using magento2 installer,using setup-script,automatically add folder in at the time of module install\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/add-directory-using-setup-script-magento2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/add-directory-using-setup-script-magento2\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/add-directory-using-setup-script-magento2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to add directory using setup script in Magento2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/ae41bc19a6783d2f09c6b9b3a0fbddfd\",\"name\":\"Shubham Sharma\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/cdf13545eee5ced4cecd7bd6cb94c1d842ec000d359f91dd900e0feec6242c3b?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/cdf13545eee5ced4cecd7bd6cb94c1d842ec000d359f91dd900e0feec6242c3b?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Shubham Sharma\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/shubham-sharma967\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to add directory using setup script in Magento2","description":"How to add directory using setup script in Magento2,using magento2 installer,using setup-script,automatically add folder in at the time of module install","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:\/\/webkul.com\/blog\/add-directory-using-setup-script-magento2\/","og_locale":"en_US","og_type":"article","og_title":"How to add directory using setup script in Magento2","og_description":"How to add directory using setup script in Magento2,using magento2 installer,using setup-script,automatically add folder in at the time of module install","og_url":"https:\/\/webkul.com\/blog\/add-directory-using-setup-script-magento2\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2016-09-09T16:21:34+00:00","article_modified_time":"2024-03-22T10:07:50+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png","type":"image\/png"}],"author":"Shubham Sharma","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Shubham Sharma","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/add-directory-using-setup-script-magento2\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/add-directory-using-setup-script-magento2\/"},"author":{"name":"Shubham Sharma","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/ae41bc19a6783d2f09c6b9b3a0fbddfd"},"headline":"How to add directory using setup script in Magento2","datePublished":"2016-09-09T16:21:34+00:00","dateModified":"2024-03-22T10:07:50+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/add-directory-using-setup-script-magento2\/"},"wordCount":69,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"keywords":["How to add directory using setup script in magento2","magento","Magento2","webkul"],"articleSection":["Magento2"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/add-directory-using-setup-script-magento2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/add-directory-using-setup-script-magento2\/","url":"https:\/\/webkul.com\/blog\/add-directory-using-setup-script-magento2\/","name":"How to add directory using setup script in Magento2","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"datePublished":"2016-09-09T16:21:34+00:00","dateModified":"2024-03-22T10:07:50+00:00","description":"How to add directory using setup script in Magento2,using magento2 installer,using setup-script,automatically add folder in at the time of module install","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/add-directory-using-setup-script-magento2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/add-directory-using-setup-script-magento2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/add-directory-using-setup-script-magento2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to add directory using setup script in Magento2"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/ae41bc19a6783d2f09c6b9b3a0fbddfd","name":"Shubham Sharma","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/cdf13545eee5ced4cecd7bd6cb94c1d842ec000d359f91dd900e0feec6242c3b?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cdf13545eee5ced4cecd7bd6cb94c1d842ec000d359f91dd900e0feec6242c3b?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Shubham Sharma"},"url":"https:\/\/webkul.com\/blog\/author\/shubham-sharma967\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/59067","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/115"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=59067"}],"version-history":[{"count":11,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/59067\/revisions"}],"predecessor-version":[{"id":429249,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/59067\/revisions\/429249"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=59067"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=59067"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=59067"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}