CINXE.COM

class IO::Path | Raku Documentation

<!DOCTYPE html> <html lang="en" class="fontawesome-i2svg-active fontawesome-i2svg-complete" style="scroll-padding-top:60px"> <head> <title>class IO::Path | Raku Documentation</title> <meta charset="UTF-8" /> <link href="/assets/images/Camelia.ico" rel="icon" type="image/x-icon"/> <link rel="stylesheet" href="/assets/css/Website.css"/> <link rel="stylesheet" href="/assets/css/listf-styling-light.css" title="light"/> <link rel="stylesheet" href="/assets/css/listf-styling-dark.css" title="dark"/> <link rel="stylesheet" href="/assets/css/css/announce-light.css" title="light"/> <link rel="stylesheet" href="/assets/css/css/announce-dark.css" title="dark"/> <link rel="stylesheet" href="/assets/css/css/options-search-light.css" title="light"/> <link rel="stylesheet" href="/assets/css/css/options-search-dark.css" title="dark"/> <link rel="stylesheet" href="/assets/css/typegraph-styling.css"/> <link rel="stylesheet" href="/assets/css/typegraph-dark.css" title="dark"/> <link rel="stylesheet" href="/assets/css/typegraph-light.css" title="light"/> <link rel="stylesheet" href="/assets/css/css/filtered-toc-dark.css" title="dark"/> <link rel="stylesheet" href="/assets/css/css/filtered-toc-light.css" title="light"/> <link rel="stylesheet" href="/assets/css/css/rainbow-dark.css" title="dark"/> <link rel="stylesheet" href="/assets/css/css/rainbow-light.css" title="light"/> <link rel="stylesheet" href="/assets/css/all.min.css"/> <link rel="stylesheet" href="/assets/css/tm-styling.css"/> <link rel="stylesheet" href="/assets/css/tm-light.css" title="light"/> <link rel="stylesheet" href="/assets/css/tm-dark.css" title="dark"/> <link rel="stylesheet" href="/assets/css/css/page-styling-main.css"/> <link rel="stylesheet" href="/assets/css/css/page-styling-dark.css" title="dark"/> <link rel="stylesheet" href="/assets/css/css/page-styling-light.css" title="light"/> <link rel="stylesheet" href="/assets/css/css/chyronToggle-dark.css" title="dark"/> <link rel="stylesheet" href="/assets/css/css/chyronToggle-light.css" title="light"/> <link rel="stylesheet" href="/assets/css/css/centreToggle-dark.css" title="dark"/> <link rel="stylesheet" href="/assets/css/css/centreToggle-light.css" title="light"/> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@tarekraafat/autocomplete.js@10.2.7/dist/css/autoComplete.min.css" /> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/atom-one-light.min.css" title="light" /> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/atom-one-dark.min.css" title="dark" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <script src="/assets/scripts/all.min.js"></script><script src="/assets/scripts/tableManager.js"></script><script src="/assets/scripts/filter-script.js"></script><script src="https://cdn.jsdelivr.net/npm/@tarekraafat/autocomplete.js@10.2.7/dist/autoComplete.min.js"></script><script src="https://cdn.jsdelivr.net/npm/fuzzysort@2.0.4/fuzzysort.min.js"></script><script src="/assets/scripts/options-search.js"></script><script src="/assets/scripts/filtered-toc.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/haskell.min.js"></script><script src="/assets/scripts/page-styling.js"></script><script src="/assets/scripts/announcements.js"></script><script src="/assets/scripts/rainbow.js"></script> </head> <body class="has-navbar-fixed-top"> <div id="class_IO::Path" class="top-of-page"></div> <nav class="navbar is-fixed-top is-flex-touch" role="navigation" aria-label="main navigation"> <div class="navbar-item" style="margin-left: auto;"> <div class="left-bar-toggle" title="Toggle Table of Contents & Index"> <label class="chyronToggle left"> <input id="navbar-left-toggle" type="checkbox"> <span class="text">Contents</span> </label> </div> </div> <div class="container is-justify-content-space-around"> <div class="navbar-brand"> <div class="navbar-logo"> <a class="navbar-item" href="/"> <img src="/assets/images/camelia-recoloured.png" alt="Raku" width="52.83" height="38"> </a> <span class="navbar-logo-tm">tm</span> </div> <a role="button" class="navbar-burger burger" aria-label="menu" aria-expanded="false" data-target="navMenu"> <span aria-hidden="true"></span> <span aria-hidden="true"></span> <span aria-hidden="true"></span> </a> </div> <div id="navMenu" class="navbar-menu"> <div class="navbar-start"> <a class="navbar-item" href="/introduction" title="Getting started, Tutorials, Migration guides"> Introduction </a> <a class="navbar-item" href="/reference" title="Fundamentals, General reference"> Reference </a> <a class="navbar-item" href="/miscellaneous" title="Programs, Experimental"> Miscellaneous </a> <a class="navbar-item" href="/types" title="The core types (classes) available"> Types </a> <a class="navbar-item" href="/routines" title="Searchable table of routines"> Routines </a> <a class="navbar-item" href="https://raku.org" title="Home page for community"> Raku<sup>®</sup> </a> <a class="navbar-item" href="https://web.libera.chat/#raku" title="IRC live chat"> Chat </a> <div class="navbar-item has-dropdown is-hoverable"> <a class="navbar-link"> More </a> <div class="navbar-dropdown is-right is-rounded"> <hr class="navbar-divider"> <a class="navbar-item js-modal-trigger" data-target="download-ebook"> Download E-Book (epub) </a> <hr class="navbar-divider"> <a class="navbar-item" href="/about"> About </a> <hr class="navbar-divider"> <a class="navbar-item has-text-red" href="https://github.com/raku/doc-website/issues"> Report an issue with this site </a> <hr class="navbar-divider"> <a class="navbar-item" href="https://github.com/raku/doc/issues"> Report an issue with the documentation content </a> <hr class="navbar-divider"> <label class="navbar-item centreToggle" title="Enable/Disable Announcements" style="--switch-width: 18"> <input id="cancelAnnouncements" type="checkbox"> <span class="text">Announcements</span> <span class="on">suppressed</span> <span class="off">allowed</span> </label> </div> </div> </div> <div class="navbar-end navbar-search-wrapper"> <div class="navbar-item"> <div class="field has-addons"> <div class="autoComplete_options"> <input class="control input" id="autoComplete" type="search" dir="ltr" spellcheck=false autocorrect="off" autocomplete="off" autocapitalize="off" placeholder="🔍 Type f to search for ..."> </div> <div class="control" title="Search options"> <a class="button is-primary js-modal-trigger" data-target="options-search-info"> <span class="icon"> <i class="fas fa-cogs"></i> </span> </a> </div> </div> </div> </div> <div id="options-search-info" class="modal"> <div class="modal-background"></div> <div class="modal-content"> <div class="box"> <p>The last search was: <span id="selected-candidate" class="ss-selected"></span></p> <div class="control is-grouped is-grouped-centered options-search-controls"> <label class="centreToggle" title="Include extra information (Alt-E)" style="--switch-width: 10.5"> <input id="options-search-extra" type="checkbox"> <span class="text">Extra info</span> <span class="on">yes</span> <span class="off">no</span> </label> <p>The search response can be shortened by excluding the extra information line (Alt-E)</p> <label class="centreToggle" title="Search engine type Strict/Loose (Alt-L)" style="--switch-width: 10.5"> <input id="options-search-loose" type="checkbox"> <span class="text">Search type</span> <span class="on">loose</span> <span class="off">strict</span> </label> <p> The search engine can perform a strict search (only the characters in the search box) or a loose search (Alt-L)</p> <label class="centreToggle" title="Search in headings (Alt-H)" style="--switch-width: 10.5"> <input id="options-search-headings" type="checkbox"> <span class="text">Headings</span> <span class="on">yes</span> <span class="off">no</span> </label> <p>Search through headings in all web-pages (Alt-H)</p> <label class="centreToggle" title="Search indexed items (Alt-I)" style="--switch-width: 10.5"> <input id="options-search-indexed" type="checkbox"> <span class="text">Indexed</span> <span class="on">yes</span> <span class="off">no</span> </label> <p>Search through all indexed items (Alt-I)</p> <label class="centreToggle" title="Search composite pages (Alt-C)" style="--switch-width: 10.5"> <input id="options-search-composite" type="checkbox"> <span class="text">Composite</span> <span class="on">yes</span> <span class="off">no</span> </label> <p>Search in the names of composite pages, which combine similar information from the main web pages (Alt-C)</p> <label class="centreToggle" title="Search primary sources (Alt-P)" style="--switch-width: 10.5"> <input id="options-search-primary" type="checkbox"> <span class="text">Primary</span> <span class="on">yes</span> <span class="off">no</span> </label> <p>Search through the names of the main web pages (Alt-P)</p> <label class="centreToggle" title="Open in new tab (Alt-Q)" style="--switch-width: 10.5"> <input id="options-search-newtab" type="checkbox"> <span class="text">New tab</span> <span class="on">yes</span> <span class="off">no</span> </label> <p>Once a search candidate has been chosen, it can be opened in a new tab or in the current tab (Alt-Q)</p> <p>If all else fails, an item is added to use the Google search engine on the whole site</p> <button class="button is-warning" id="options-search-reset-defaults">Clear options, reset to defaults</button> <p>Exit this page by pressing &lt;Escape&gt;, or clicking on X or on the background.</p> </div> </div> </div> <button class="modal-close is-large" aria-label="close"></button> </div> </div> <div id="download-ebook" class="modal"> <div class="modal-background"></div> <div class="modal-content"> <div class="box"> <p><a href="/RakuDocumentation.epub" download>RakuDocumentation.epub</a> is a work in progress e-book. It targets the <a href="https://www.w3.org/publishing/epub3/">EPUB v3 specification</a>. It needs testing on a variety of ereaders (some of which may still implicitly expect compliance with EPUB v2). The CSS definitely needs enhancing (especially for code snippets). The Ebook opens in a Calibre reader, which is available on all operating systems.</p> <p>Suggestions are welcome and should be addressed by opening an issue on the Raku/doc-website repository</p> <p>Exit this popup by pressing &lt;Escape&gt;, or clicking on X or on the background.</p> </div> </div> <button class="modal-close is-large" aria-label="close"></button> </div> <div id="announcement-modal" class="modal"> <div class="modal-background"></div> <div class="modal-content"> <div class="box"> <div id="raku-doc-announcement"></div> <p>For more see <a href="/announcements">Announcements page</a>.</p> <p>Exit this popup by pressing &lt;Escape&gt;, or clicking on X or on the background.</p> </div> </div> <button class="modal-close is-large" aria-label="close"></button> </div> </div> </nav> <div class="tile is-ancestor section"> <div class="page-edit"> <a class="button page-edit-button" href="https://github.com/Raku/doc/edit/main/doc/Type/IO/Path.rakudoc" title="Edit this page.&#13;Commit: 3ed988e34 2024-08-04"> <span class="icon is-right"> <i class="fas fa-pen-alt is-medium"></i> </span> </a> </div> <div id="left-column" class="tile is-parent is-2 is-hidden"> <div id="left-col-inner"> <div class="tabs" id="tabs"> <ul> <li class="is-active" id="toc-tab"> <a>Table of Contents</a> </li> <li id="index-tab"> <a>Index</a> </li> </ul> </div> <div class="field"> <div class="control has-icons-right"> <input id="toc-filter" class="input" type="text" placeholder="Filter"> <span class="icon is-right has-text-grey"> <i class="fas fa-search is-medium"></i> </span> </div> </div> <div class="raku-sidebar"> <aside id="toc-menu" class="menu"> <ul class="menu-list"> <li><a href="#Methods">Methods</a></li> <ul> <li><a href="#method_new">method new</a></li> <li><a href="#attribute_CWD">attribute CWD</a></li> <li><a href="#attribute_SPEC">attribute SPEC</a></li> <li><a href="#attribute_path">attribute path</a></li> <li><a href="#method_ACCEPTS">method ACCEPTS</a></li> <li><a href="#method_basename">method basename</a></li> <li><a href="#method_add">method add</a></li> <li><a href="#method_child">method child</a></li> <li><a href="#method_cleanup">method cleanup</a></li> <li><a href="#method_comb">method comb</a></li> <li><a href="#method_split">method split</a></li> <li><a href="#method_extension">method extension</a></li> <li><a href="#method_dirname">method dirname</a></li> <li><a href="#method_volume">method volume</a></li> <li><a href="#method_parts">method parts</a></li> <li><a href="#method_raku">method raku</a></li> <li><a href="#method_gist">method gist</a></li> <li><a href="#method_Str">method Str</a></li> <li><a href="#method_succ">method succ</a></li> <li><a href="#method_open">method open</a></li> <li><a href="#method_pred">method pred</a></li> <li><a href="#method_watch">method watch</a></li> <li><a href="#method_is-absolute">method is-absolute</a></li> <li><a href="#method_is-relative">method is-relative</a></li> <li><a href="#method_absolute">method absolute</a></li> <li><a href="#method_relative">method relative</a></li> <li><a href="#method_parent">method parent</a></li> <li><a href="#method_resolve">method resolve</a></li> <li><a href="#routine_dir">routine dir</a></li> <li><a href="#File_test_operators">File test operators</a></li> <li><a href="#method_e">method e</a></li> <li><a href="#method_d">method d</a></li> <li><a href="#method_f">method f</a></li> <li><a href="#method_s">method s</a></li> <li><a href="#method_l">method l</a></li> <li><a href="#method_r">method r</a></li> <li><a href="#method_w">method w</a></li> <li><a href="#method_rw">method rw</a></li> <li><a href="#method_x">method x</a></li> <li><a href="#method_rwx">method rwx</a></li> <li><a href="#method_z">method z</a></li> <li><a href="#method_sibling">method sibling</a></li> <li><a href="#method_words">method words</a></li> <li><a href="#method_lines">method lines</a></li> <li><a href="#routine_slurp">routine slurp</a></li> <li><a href="#method_spurt">method spurt</a></li> <li><a href="#method_chdir">method chdir</a></li> <li><a href="#method_mkdir">method mkdir</a></li> <li><a href="#routine_rmdir">routine rmdir</a></li> <li><a href="#method_chmod">method chmod</a></li> <li><a href="#routine_rename">routine rename</a></li> <li><a href="#routine_copy">routine copy</a></li> <li><a href="#routine_move">routine move</a></li> <li><a href="#method_Numeric">method Numeric</a></li> <li><a href="#method_Int">method Int</a></li> <li><a href="#routine_symlink">routine symlink</a></li> <li><a href="#routine_link">routine link</a></li> <li><a href="#routine_unlink">routine unlink</a></li> <li><a href="#routine_chown">routine chown</a></li> <li><a href="#method_IO">method IO</a></li> <li><a href="#method_SPEC">method SPEC</a></li> </ul> <li><a href="#File_timestamp_retrieval">File timestamp retrieval</a></li> <ul> <li><a href="#method_created">method created</a></li> <li><a href="#method_modified">method modified</a></li> <li><a href="#method_accessed">method accessed</a></li> <li><a href="#method_changed">method changed</a></li> </ul> <li><a href="#File_permissions_retrieval">File permissions retrieval</a></li> <ul> <li><a href="#method_mode">method mode</a></li> </ul> <li><a href="#Other_informational_methods">Other informational methods</a></li> <ul> <li><a href="#method_user">method user</a></li> <li><a href="#method_group">method group</a></li> <li><a href="#method_dir-with-entries">method dir-with-entries</a></li> <li><a href="#method_inode">method inode</a></li> <li><a href="#method_dev">method dev</a></li> <li><a href="#method_devtype">method devtype</a></li> </ul> </aside> <aside id="index-menu" class="menu is-hidden"> </aside> </div> </div> </div> <div id="main-column" class="tile is-parent" style="overflow-x: hidden;"> <div id="main-col-inner"> <section class="raku page-header"> <div class="container px-4"> <div class="raku page-title has-text-centered"> class IO::Path </div> <div class="raku page-subtitle has-text-centered"> <p>File or directory path</p> </div> </div> </section> <section class="raku page-content"><div class="container px-4"><div class="columns one-col"> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">class</span> <span class="highlite-TYPE">IO::Path</span> <span class="highlite-KEYWORD">is</span> <span class="highlite-TYPE">Cool</span> <span class="highlite-KEYWORD">does</span> <span class="highlite-TYPE">IO</span> { } </pre> </div> </div> <p><code>IO::Path</code> is the workhorse of IO operations.</p><p>Conceptually, an <code>IO::Path</code> object consists of a volume, a directory, and a basename. It supports both purely textual operations, and operations that access the filesystem, e.g. to resolve a path, or to read all the content of a file.</p><p>At creation, each <code>IO::Path</code> object is given information about the current working directory the path might be relative to using the <code>$.CWD</code> attribute (defaults to <a href="/language/variables#Dynamic_variables"><code>$*CWD</code></a>), as well as what operating system semantics should be used for path manipulation using the special <a href="/type/IO/Spec"><code>IO::Spec</code></a> type given in the <code>$.SPEC</code> attribute.</p><p>The <code>$.SPEC</code> defaults to the value of <a href="/language/variables#Dynamic_variables"><code>$*SPEC</code></a>, which uses the object suitable for the operating system the code is currently running on. This is the default most code will be comfortable with.</p><p>In certain situations, e.g. testing, you may wish to force <code>$*SPEC</code> to use one of the specific SPEC modules: <a href="/type/IO/Spec/Unix"><code>IO::Spec::Unix</code></a>, <a href="/type/IO/Spec/Win32"><code>IO::Spec::Win32</code></a>, <a href="/type/IO/Spec/Cygwin"><code>IO::Spec::Cygwin</code></a>, and <a href="/type/IO/Spec/QNX"><code>IO::Spec::QNX</code></a>, or to create <code>IO::Path</code> objects via shortcut subclasses <a href="/type/IO/Path/Unix"><code>IO::Path::Unix</code></a>, <a href="/type/IO/Path/Win32"><code>IO::Path::Win32</code></a>, <a href="/type/IO/Path/Cygwin"><code>IO::Path::Cygwin</code></a>, and <a href="/type/IO/Path/QNX"><code>IO::Path::QNX</code></a> that pre-set the <code>$.SPEC</code> attribute for you.</p><p>The rest of this document silently assumes Unix semantics in its examples, unless stated otherwise.</p> <h1 id="Methods" class="raku-h1"><a href="#class_IO::Path" title="go to top of document">Methods<a class="raku-anchor" title="direct link" href="#Methods">§</a></a></h1> <h2 id="method_new" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method new<a class="raku-anchor" title="direct link" href="#method_new">§</a></a></h2> <!-- defnmark method_new 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">multi</span> <span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">new</span>(Str:D <span class="highlite-NAME_SCALAR">$path</span><span class="highlite-OPERATOR">,</span> <span class="highlite-TYPE">IO::Spec</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$SPEC</span> <span class="highlite-OPERATOR">=</span> <span class="highlite-NAME_SCALAR">$*SPEC</span><span class="highlite-OPERATOR">,</span> <span class="highlite-TYPE">Str</span>() <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$CWD</span> <span class="highlite-OPERATOR">=</span> <span class="highlite-NAME_SCALAR">$*CWD</span>) <span class="highlite-KEYWORD">multi</span> <span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">new</span>( <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$basename</span>!<span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$dirname</span> <span class="highlite-OPERATOR">=</span> <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">.</span><span class="highlite-STRING_DELIMITER">'</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$volume</span> <span class="highlite-OPERATOR">=</span> <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING_DELIMITER">'</span> <span class="highlite-TYPE">IO::Spec</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$SPEC</span> <span class="highlite-OPERATOR">=</span> <span class="highlite-NAME_SCALAR">$*SPEC</span><span class="highlite-OPERATOR">,</span> <span class="highlite-TYPE">Str</span>() <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$CWD</span> <span class="highlite-OPERATOR">=</span> <span class="highlite-NAME_SCALAR">$*CWD</span> ) </pre> </div> </div> <p>Creates a new <code>IO::Path</code> object from a path string (which is being parsed for volume, directory name and basename), or from volume, directory name and basename passed as named arguments.</p><p>The path's operation will be performed using <code>:$SPEC</code> semantics (defaults to current <a href="/language/variables#Dynamic_variables"><code>$*SPEC</code></a>) and will use <code>:$CWD</code> as the directory the path is relative to (defaults to <a href="/language/variables#Dynamic_variables"><code>$*CWD</code></a>).</p><p>If <code>$path</code> includes the null byte, it will throw an Exception with a &quot;Cannot use null character (U+0000) as part of the path&quot; message.</p> <h2 id="attribute_CWD" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">attribute CWD<a class="raku-anchor" title="direct link" href="#attribute_CWD">§</a></a></h2> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-TYPE">IO::Path</span>.<span class="highlite-ROUTINE">new</span>(<span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo</span><span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-OPERATOR">,</span> :CWD&lt;/home/camelia&gt;) .CWD.<span class="highlite-ROUTINE">say</span>; <span class="highlite-COMMENT"># OUTPUT: «/home/camelia␤»</span></pre> </div> </div> <p>Read-only. Contains implicit or explicit value of <code>:$CWD</code> argument to <code>.new</code>.</p> <h2 id="attribute_SPEC" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">attribute SPEC<a class="raku-anchor" title="direct link" href="#attribute_SPEC">§</a></a></h2> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-TYPE">IO::Path</span>.<span class="highlite-ROUTINE">new</span>(<span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo</span><span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-OPERATOR">,</span> :SPEC(<span class="highlite-TYPE">IO::Spec::Unix</span>.<span class="highlite-ROUTINE">new</span>))\ .<span class="highlite-ROUTINE">SPEC</span>.^<span class="highlite-ROUTINE">name</span>.<span class="highlite-ROUTINE">say</span>; <span class="highlite-COMMENT"># OUTPUT: «IO::Spec::Unix␤»</span></pre> </div> </div> <p>Read-only. Contains implicit or explicit value of <code>:$SPEC</code> argument to <code>.new</code>.</p> <h2 id="attribute_path" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">attribute path<a class="raku-anchor" title="direct link" href="#attribute_path">§</a></a></h2> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-TYPE">IO::Path</span>.<span class="highlite-ROUTINE">new</span>(<span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo</span><span class="highlite-STRING_DELIMITER">&quot;</span>).<span class="highlite-ROUTINE">path</span>.<span class="highlite-ROUTINE">say</span>; <span class="highlite-COMMENT"># OUTPUT: «foo␤»</span></pre> </div> </div> <p>Read-only. Returns the string the object was constructed from or the value of <code>$SPEC.join($volume, $dirname, $basename)</code> if multi-part version of <code>.new</code> was used. <strong>NOTE:</strong> this does not include the <code>$.CWD</code>; see <a href="/routine/absolute"><code>IO::Path.absolute</code></a> and <a href="/routine/relative"><code>IO::Path.relative</code></a> for stringification options that include <code>$.CWD</code>.</p><p><strong>NOTE:</strong> Implementations may cache operations done with this attribute, so modifying its value (via cloning or Proxy) is NOT recommended and may result in broken <code>IO::Path</code> objects. Create a new <code>IO::Path</code> object instead.</p> <h2 id="method_ACCEPTS" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method ACCEPTS<a class="raku-anchor" title="direct link" href="#method_ACCEPTS">§</a></a></h2> <!-- defnmark method_ACCEPTS 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">multi</span> <span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">ACCEPTS</span>(IO::Path:D: Cool:D <span class="highlite-NAME_SCALAR">$other</span> <span class="highlite-KEYWORD">--&gt;</span> Bool:D)</pre> </div> </div> <p>Coerces the argument to <code>IO::Path</code>, if necessary. Returns <code>True</code> if <a href="/routine/absolute"><code>.absolute</code></a> method on both paths returns the same string. <strong>NOTE:</strong> it's possible for two paths that superficially point to the same resource to NOT smartmatch as <code>True</code>, if they were constructed differently and were never fully resolved:</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo/../bar</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span> <span class="highlite-OPERATOR">~~</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">bar</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span> <span class="highlite-COMMENT"># False</span></pre> </div> </div> <p>The reason is the two paths above may point to different resources when fully resolved (e.g. if <code>foo</code> is a symlink). Resolve the paths before smartmatching to check they point to same resource:</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo/../bar</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">resolve</span>(:completely) <span class="highlite-OPERATOR">~~</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">bar</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">resolve</span>(:completely) <span class="highlite-COMMENT"># True</span></pre> </div> </div> <h2 id="method_basename" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method basename<a class="raku-anchor" title="direct link" href="#method_basename">§</a></a></h2> <!-- defnmark method_basename 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">basename</span>(IO::Path:D:)</pre> </div> </div> <p>Returns the basename part of the path object, which is the name of the filesystem object itself that is referenced by the path.</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">docs/README.pod</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">basename</span>.<span class="highlite-ROUTINE">say</span>; <span class="highlite-COMMENT"># OUTPUT: «README.pod␤» </span><span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">/tmp/</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">basename</span>.<span class="highlite-ROUTINE">say</span>; <span class="highlite-COMMENT"># OUTPUT: «tmp␤»</span></pre> </div> </div> <p>Note that in <a href="/type/IO/Spec/Win32"><code>IO::Spec::Win32</code></a> semantics, the <code>basename</code> of a Windows share is <code>\</code>, not the name of the share itself:</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-TYPE">IO::Path::Win32</span>.<span class="highlite-ROUTINE">new</span>(<span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">//server/share</span><span class="highlite-STRING_DELIMITER">'</span>).<span class="highlite-ROUTINE">basename</span>.<span class="highlite-ROUTINE">say</span>; <span class="highlite-COMMENT"># OUTPUT: «\␤»</span></pre> </div> </div> <h2 id="method_add" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method add<a class="raku-anchor" title="direct link" href="#method_add">§</a></a></h2> <!-- defnmark method_add 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">add</span>(IO::Path:D: <span class="highlite-TYPE">Str</span>() <span class="highlite-NAME_SCALAR">$what</span> <span class="highlite-KEYWORD">--&gt;</span> IO::Path:D)</pre> </div> </div> <p>Concatenates a path fragment to the invocant and returns the resultant <code>IO::Path</code>. If adding <code>../</code> to paths that end with a file, you may need to call <a href="/routine/resolve">resolve</a> for the resultant path to be accessible by other <code>IO::Path</code> methods like <a href="/routine/dir">dir</a> or <a href="/routine/open">open</a>. See also <a href="/routine/sibling">sibling</a> and <a href="/routine/parent">parent</a>.</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo/bar</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">mkdir</span>; <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo/bar</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">add</span>(<span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">meow</span><span class="highlite-STRING_DELIMITER">&quot;</span>) .<span class="highlite-ROUTINE">resolve</span>.<span class="highlite-ROUTINE">relative</span>.<span class="highlite-ROUTINE">say</span>; <span class="highlite-COMMENT"># OUTPUT: «foo/bar/meow␤» </span><span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo/bar</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">add</span>(<span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">/meow</span><span class="highlite-STRING_DELIMITER">&quot;</span>) .<span class="highlite-ROUTINE">resolve</span>.<span class="highlite-ROUTINE">relative</span>.<span class="highlite-ROUTINE">say</span>; <span class="highlite-COMMENT"># OUTPUT: «foo/bar/meow␤» </span><span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo/bar</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">add</span>(<span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">meow.txt</span><span class="highlite-STRING_DELIMITER">&quot;</span>).<span class="highlite-ROUTINE">resolve</span>.<span class="highlite-ROUTINE">relative</span>.<span class="highlite-ROUTINE">say</span>; <span class="highlite-COMMENT"># OUTPUT: «foo/bar/meow.txt␤» </span><span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo/bar</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">add</span>(<span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">../meow</span><span class="highlite-STRING_DELIMITER">&quot;</span>) .<span class="highlite-ROUTINE">resolve</span>.<span class="highlite-ROUTINE">relative</span>.<span class="highlite-ROUTINE">say</span>; <span class="highlite-COMMENT"># OUTPUT: «foo/meow␤» </span><span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo/bar</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">add</span>(<span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">../../</span><span class="highlite-STRING_DELIMITER">&quot;</span>) .<span class="highlite-ROUTINE">resolve</span>.<span class="highlite-ROUTINE">relative</span>.<span class="highlite-ROUTINE">say</span>; <span class="highlite-COMMENT"># OUTPUT: «.␤» </span> <span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">add</span>(IO::Path:D: <span class="highlite-OPERATOR">*</span><span class="highlite-NAME_ARRAY">@parts</span> <span class="highlite-KEYWORD">--&gt;</span> IO::Path:D)</pre> </div> </div> <p>As of release 2021.07 of the Rakudo compiler, it is also possible to specify multiple parts to be added to a path.</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">add</span>(<span class="highlite-STRING_DELIMITER">&lt;</span><span class="highlite-STRING">bar baz</span><span class="highlite-STRING_DELIMITER">&gt;</span>).<span class="highlite-ROUTINE">resolve</span>.<span class="highlite-ROUTINE">relative</span>.<span class="highlite-ROUTINE">say</span>; <span class="highlite-COMMENT"># OUTPUT: «foo/bar/baz␤»</span></pre> </div> </div> <h2 id="method_child" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method child<a class="raku-anchor" title="direct link" href="#method_child">§</a></a></h2> <!-- defnmark method_child 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">child</span>(IO::Path:D: <span class="highlite-TYPE">Str</span>() <span class="highlite-NAME_SCALAR">$childname</span> <span class="highlite-KEYWORD">--&gt;</span> IO::Path:D)</pre> </div> </div> <p>Alias for <a href="/routine/add"><code>.add</code></a>.</p> <h2 id="method_cleanup" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method cleanup<a class="raku-anchor" title="direct link" href="#method_cleanup">§</a></a></h2> <!-- defnmark method_cleanup 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">cleanup</span>(IO::Path:D: <span class="highlite-KEYWORD">--&gt;</span> IO::Path:D)</pre> </div> </div> <p>Returns a new path that is a canonical representation of the invocant path, cleaning up any extraneous path parts:</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo/./././..////bar</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">cleanup</span>.<span class="highlite-ROUTINE">say</span>; <span class="highlite-COMMENT"># OUTPUT: «&quot;foo/../bar&quot;.IO␤» </span><span class="highlite-TYPE">IO::Path::Win32</span>.<span class="highlite-ROUTINE">new</span>(<span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo/./././..////bar</span><span class="highlite-STRING_DELIMITER">&quot;</span>) .<span class="highlite-ROUTINE">cleanup</span>.<span class="highlite-ROUTINE">say</span>; <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo</span><span class="highlite-ESCAPE">\.</span><span class="highlite-STRING">.</span><span class="highlite-ESCAPE">\b</span><span class="highlite-STRING">ar</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>; <span class="highlite-COMMENT"># OUTPUT: «&quot;foo\..\bar&quot;.IO␤»</span></pre> </div> </div> <p>Note that no filesystem access is made. See also <a href="/routine/resolve"><code>resolve</code></a>.</p> <h2 id="method_comb" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method comb<a class="raku-anchor" title="direct link" href="#method_comb">§</a></a></h2> <!-- defnmark method_comb 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">comb</span>(IO::Path:D: |<span class="highlite-ROUTINE">args</span> <span class="highlite-KEYWORD">--&gt;</span> Seq:D)</pre> </div> </div> <p>Opens the file and processes its contents the same way <a href="/type/Str#routine_comb"><code>Str.comb</code></a> does, taking the same arguments. Implementations may slurp the file in its entirety when this method is called.</p> <h2 id="method_split" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method split<a class="raku-anchor" title="direct link" href="#method_split">§</a></a></h2> <!-- defnmark method_split 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">split</span>(IO::Path:D: |<span class="highlite-ROUTINE">args</span> <span class="highlite-KEYWORD">--&gt;</span> Seq:D)</pre> </div> </div> <p>Opens the file and processes its contents the same way <a href="/type/Str#routine_split"><code>Str.split</code></a> does, taking the same arguments. Implementations may slurp the file in its entirety when this method is called.</p> <h2 id="method_extension" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method extension<a class="raku-anchor" title="direct link" href="#method_extension">§</a></a></h2> <!-- defnmark method_extension 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">multi</span> <span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">extension</span>(IO::Path:D: <span class="highlite-KEYWORD">--&gt;</span> Str:D) <span class="highlite-KEYWORD">multi</span> <span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">extension</span>(IO::Path:D: <span class="highlite-TYPE">Int</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$parts</span> <span class="highlite-KEYWORD">--&gt;</span> Str:D) <span class="highlite-KEYWORD">multi</span> <span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">extension</span>(IO::Path:D: <span class="highlite-TYPE">Range</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$parts</span> <span class="highlite-KEYWORD">--&gt;</span> Str:D) <span class="highlite-KEYWORD">multi</span> <span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">extension</span>(IO::Path:D: <span class="highlite-TYPE">Str</span> <span class="highlite-NAME_SCALAR">$subst</span><span class="highlite-OPERATOR">,</span> <span class="highlite-TYPE">Int</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$parts</span><span class="highlite-OPERATOR">,</span> <span class="highlite-TYPE">Str</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$joiner</span> <span class="highlite-KEYWORD">--&gt;</span> IO::Path:D) <span class="highlite-KEYWORD">multi</span> <span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">extension</span>(IO::Path:D: <span class="highlite-TYPE">Str</span> <span class="highlite-NAME_SCALAR">$subst</span><span class="highlite-OPERATOR">,</span> <span class="highlite-TYPE">Range</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$parts</span><span class="highlite-OPERATOR">,</span> <span class="highlite-TYPE">Str</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$joiner</span> <span class="highlite-KEYWORD">--&gt;</span> IO::Path:D)</pre> </div> </div> <p>Returns the extension consisting of <code>$parts</code> parts (defaults to <code>1</code>), where a &quot;part&quot; is defined as a dot followed by possibly-empty string up to the end of the string, or previous part. That is <code>&quot;foo.tar.gz&quot;</code> has an extension of two parts: first part is <code>&quot;gz&quot;</code> and second part is <code>&quot;tar&quot;</code> and calling <code>&quot;foo.tar.gz&quot;.IO.extension: :2parts</code> gives <code>&quot;tar.gz&quot;</code>. If an extension with the specified number of <code>$parts</code> is not found, returns an empty string.</p><p><code>$parts</code> can be a <a href="/type/Range"><code>Range</code></a>, specifying the minimum number of parts and maximum number of parts the extension should have. The routine will attempt to much the most parts it can. If <code>$parts</code> range's endpoints that are smaller than <code>0</code> they'll be treated as <code>0</code>; implementations may treat endpoints larger than <code>2⁶³-1</code> as <code>2⁶³-1</code>. Ranges with <code>NaN</code> or <a href="/type/Str"><code>Str</code></a> endpoints will cause an exception to be thrown.</p><p>If <code>$subst</code> is provided, the extension will be instead replaced with <code>$subst</code> and a new <code>IO::Path</code> object will be returned. It will be joined to the file's name with <code>$joiner</code>, which defaults to an empty string when <code>$subst</code> is an empty string and to <code>&quot;.&quot;</code> when <code>$subst</code> is not empty. <strong>Note:</strong> if as the result of replacement the <a href="/routine/basename"><code>basename</code></a> of the path ends up being empty, it will be assumed to be <code>.</code> (a single dot).</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-COMMENT"># Getting an extension: </span><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo.tar.gz</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">extension</span>; <span class="highlite-COMMENT"># OUTPUT: «gz␤» </span><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo.tar.gz</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.extension: :2parts; <span class="highlite-COMMENT"># OUTPUT: «tar.gz␤» </span><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo.tar.gz</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.extension: :parts(^5); <span class="highlite-COMMENT"># OUTPUT: «tar.gz␤» </span><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo.tar.gz</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.extension: :parts(0..1); <span class="highlite-COMMENT"># OUTPUT: «gz␤» </span> <span class="highlite-COMMENT"># Replacing an extension </span><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo.tar.gz</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.extension: <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING_DELIMITER">'</span>; <span class="highlite-COMMENT"># OUTPUT: «&quot;foo.tar&quot;.IO␤» </span><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo.tar.gz</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.extension: <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">ZIP</span><span class="highlite-STRING_DELIMITER">'</span>; <span class="highlite-COMMENT"># OUTPUT: «&quot;foo.tar.ZIP&quot;.IO␤» </span><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo.tar.gz</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.extension: <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">ZIP</span><span class="highlite-STRING_DELIMITER">'</span><span class="highlite-OPERATOR">,</span> :0parts; <span class="highlite-COMMENT"># OUTPUT: «&quot;foo.tar.gz.ZIP&quot;.IO␤» </span><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo.tar.gz</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.extension: <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">ZIP</span><span class="highlite-STRING_DELIMITER">'</span><span class="highlite-OPERATOR">,</span> :2parts; <span class="highlite-COMMENT"># OUTPUT: «&quot;foo.ZIP&quot;.IO␤» </span><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo.tar.gz</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.extension: <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">ZIP</span><span class="highlite-STRING_DELIMITER">'</span><span class="highlite-OPERATOR">,</span> :parts(^5); <span class="highlite-COMMENT"># OUTPUT: «&quot;foo.ZIP&quot;.IO␤» </span> <span class="highlite-COMMENT"># Replacing an extension using non-standard joiner: </span><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo.tar.gz</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.extension: <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING_DELIMITER">'</span><span class="highlite-OPERATOR">,</span> :joiner&lt;_&gt;; <span class="highlite-COMMENT"># OUTPUT: «&quot;foo.tar_&quot;.IO␤» </span><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo.tar.gz</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.extension: <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">ZIP</span><span class="highlite-STRING_DELIMITER">'</span><span class="highlite-OPERATOR">,</span> :joiner&lt;_&gt;; <span class="highlite-COMMENT"># OUTPUT: «&quot;foo.tar_ZIP&quot;.IO␤» </span><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo.tar.gz</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.extension: <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">ZIP</span><span class="highlite-STRING_DELIMITER">'</span><span class="highlite-OPERATOR">,</span> :joiner&lt;_&gt;<span class="highlite-OPERATOR">,</span> :2parts; <span class="highlite-COMMENT"># OUTPUT: «&quot;foo_ZIP&quot;.IO␤» </span><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo.tar.gz</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.extension: <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">ZIP</span><span class="highlite-STRING_DELIMITER">'</span><span class="highlite-OPERATOR">,</span> :joiner&lt;_&gt;<span class="highlite-OPERATOR">,</span> :parts(^5); <span class="highlite-COMMENT"># OUTPUT: «&quot;foo_ZIP&quot;.IO␤» </span> <span class="highlite-COMMENT"># EDGE CASES: </span> <span class="highlite-COMMENT"># There is no 5-part extension, so returned value is an empty string </span><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo.tar.gz</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.extension: :5parts; <span class="highlite-COMMENT"># OUTPUT: «␤» </span> <span class="highlite-COMMENT"># There is no 5-part extension, so we replaced nothing: </span><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo.tar.gz</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.extension: <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">ZIP</span><span class="highlite-STRING_DELIMITER">'</span><span class="highlite-OPERATOR">,</span> :5parts; <span class="highlite-COMMENT"># OUTPUT: «&quot;foo.tar.gz&quot;.IO␤» </span> <span class="highlite-COMMENT"># Replacing a 0-part extension is just appending: </span><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo.tar.gz</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.extension: <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">ZIP</span><span class="highlite-STRING_DELIMITER">'</span><span class="highlite-OPERATOR">,</span> :0parts; <span class="highlite-COMMENT"># OUTPUT: «&quot;foo.tar.gz.ZIP&quot;.IO␤» </span> <span class="highlite-COMMENT"># Replace 1-part of the extension, using '.' joiner </span><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">...</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.extension: <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">tar</span><span class="highlite-STRING_DELIMITER">'</span>; <span class="highlite-COMMENT"># OUTPUT: «&quot;...tar&quot;.IO␤» </span> <span class="highlite-COMMENT"># Replace 1-part of the extension, using empty string joiner </span><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">...</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.extension: <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">tar</span><span class="highlite-STRING_DELIMITER">'</span><span class="highlite-OPERATOR">,</span> :joiner(<span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING_DELIMITER">'</span>); <span class="highlite-COMMENT"># OUTPUT: «&quot;..tar&quot;.IO␤» </span> <span class="highlite-COMMENT"># Remove 1-part extension; results in empty basename, so result is &quot;.&quot;.IO </span><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">.</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.extension: <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING_DELIMITER">'</span>; <span class="highlite-COMMENT"># OUTPUT: «&quot;.&quot;.IO␤»</span></pre> </div> </div> <h2 id="method_dirname" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method dirname<a class="raku-anchor" title="direct link" href="#method_dirname">§</a></a></h2> <!-- defnmark method_dirname 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">dirname</span>(IO::Path:D:)</pre> </div> </div> <p>Returns the directory name portion of the path object. That is, it returns the path excluding the <a href="/routine/volume">volume</a> and the <a href="/routine/basename">base name</a>. Unless the dirname consist of <em>only</em> the directory separator (i.e. it's the top directory), the trailing directory separator will <em>not</em> be included in the return value.</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-ROUTINE">say</span> <span class="highlite-TYPE">IO::Path</span>.<span class="highlite-ROUTINE">new</span>(<span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">/home/camelia/myfile.raku</span><span class="highlite-STRING_DELIMITER">&quot;</span>).<span class="highlite-ROUTINE">dirname</span>; <span class="highlite-COMMENT"># OUTPUT: «/home/camelia␤» </span><span class="highlite-ROUTINE">say</span> <span class="highlite-TYPE">IO::Path::Win32</span>.<span class="highlite-ROUTINE">new</span>(<span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">C:/home/camelia</span><span class="highlite-STRING_DELIMITER">&quot;</span>).<span class="highlite-ROUTINE">dirname</span>; <span class="highlite-COMMENT"># OUTPUT: «/home␤» </span><span class="highlite-ROUTINE">say</span> <span class="highlite-TYPE">IO::Path</span>.<span class="highlite-ROUTINE">new</span>(<span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">/home</span><span class="highlite-STRING_DELIMITER">&quot;</span>).<span class="highlite-ROUTINE">dirname</span>; <span class="highlite-COMMENT"># OUTPUT: «/␤»</span></pre> </div> </div> <h2 id="method_volume" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method volume<a class="raku-anchor" title="direct link" href="#method_volume">§</a></a></h2> <!-- defnmark method_volume 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">volume</span>(IO::Path:D:)</pre> </div> </div> <p>Returns the volume portion of the path object. On Unix system, this is always the empty string.</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-ROUTINE">say</span> <span class="highlite-TYPE">IO::Path::Win32</span>.<span class="highlite-ROUTINE">new</span>(<span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">C:</span><span class="highlite-ESCAPE">\\</span><span class="highlite-STRING">Windows</span><span class="highlite-ESCAPE">\\</span><span class="highlite-STRING">registry.ini</span><span class="highlite-STRING_DELIMITER">&quot;</span>).<span class="highlite-ROUTINE">volume</span>; <span class="highlite-COMMENT"># OUTPUT: «C:␤»</span></pre> </div> </div> <h2 id="method_parts" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method parts<a class="raku-anchor" title="direct link" href="#method_parts">§</a></a></h2> <!-- defnmark method_parts 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">parts</span>(IO::Path:D:)</pre> </div> </div> <p>Returns an <a href="/type/IO/Path/Parts"><code>IO::Path::Parts</code></a> for the invocant.</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-ROUTINE">say</span> <span class="highlite-TYPE">IO::Path::Win32</span>.<span class="highlite-ROUTINE">new</span>(<span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">C:/rakudo/raku.bat</span><span class="highlite-STRING_DELIMITER">&quot;</span>).<span class="highlite-ROUTINE">parts</span>.<span class="highlite-ROUTINE">raku</span>; <span class="highlite-COMMENT"># OUTPUT: «IO::Path::Parts.new(&quot;C:&quot;,&quot;/rakudo&quot;,&quot;raku.bat&quot;)␤»</span></pre> </div> </div> <p><strong>Note</strong>: Before Rakudo version 2020.06 a <a href="/type/Map"><code>Map</code></a> was returned, with the keys <code>volume</code>, <code>dirname</code>, <code>basename</code> whose values were the respective invocant parts.</p> <h2 id="method_raku" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method raku<a class="raku-anchor" title="direct link" href="#method_raku">§</a></a></h2> <!-- defnmark method_raku 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">raku</span>(IO::Path:D: <span class="highlite-KEYWORD">--&gt;</span> Str:D)</pre> </div> </div> <p>Returns a string that, when given passed through <a href="/routine/EVAL"><code>EVAL</code></a> gives the original invocant back.</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo/bar</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">raku</span>.<span class="highlite-ROUTINE">say</span>; <span class="highlite-COMMENT"># OUTPUT: IO::Path.new(&quot;foo/bar&quot;, :SPEC(IO::Spec::Unix), :CWD(&quot;/home/camelia&quot;)) </span></pre> </div> </div> <p>Note that this string includes the value of the <code>.CWD</code> attribute that is set to <a href="/language/variables#Dynamic_variables"><code>$*CWD</code></a> when the path object was created, by default.</p> <h2 id="method_gist" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method gist<a class="raku-anchor" title="direct link" href="#method_gist">§</a></a></h2> <!-- defnmark method_gist 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">gist</span>(IO::Path:D: <span class="highlite-KEYWORD">--&gt;</span> Str:D)</pre> </div> </div> <p>Returns a string, part of which contains either the value of <a href="/type/IO/Path#method_absolute"><code>.absolute</code></a> (if path is absolute) or <a href="/type/IO/Path#attribute_path"><code>.path</code></a>. Note that no escaping of special characters is made, so e.g. <code>&quot;\b&quot;</code> means a path contains a backslash and letter &quot;b&quot;, not a backspace.</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo/bar</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>; <span class="highlite-COMMENT"># OUTPUT: «&quot;foo/bar&quot;.IO␤» </span><span class="highlite-ROUTINE">say</span> <span class="highlite-TYPE">IO::Path::Win32</span>.new: <span class="highlite-STRING_DELIMITER">「</span><span class="highlite-STRING">C:\foo/bar\</span><span class="highlite-STRING_DELIMITER">」</span>; <span class="highlite-COMMENT"># OUTPUT: «&quot;C:\foo/bar\&quot;.IO␤»</span></pre> </div> </div> <h2 id="method_Str" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method Str<a class="raku-anchor" title="direct link" href="#method_Str">§</a></a></h2> <!-- defnmark method_Str 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-TYPE">Str</span>(IO::Path:D: <span class="highlite-KEYWORD">--&gt;</span> <span class="highlite-TYPE">Str</span>)</pre> </div> </div> <p>Alias for <a href="/routine/path"><code>IO::Path.path</code></a>. In particular, note that default stringification of an <code>IO::Path</code> does <strong>NOT</strong> use the value of <a href="/type/IO/Path#attribute_CWD"><code>$.CWD</code> attribute</a>. To stringify while retaining full path information use <a href="/routine/absolute"><code>.absolute</code></a> or <a href="/routine/relative"><code>.relative</code></a> methods.</p> <h2 id="method_succ" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method succ<a class="raku-anchor" title="direct link" href="#method_succ">§</a></a></h2> <!-- defnmark method_succ 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">succ</span>(IO::Path:D: <span class="highlite-KEYWORD">--&gt;</span> IO::Path:D)</pre> </div> </div> <p>Returns a new <code>IO::Path</code> constructed from the invocant, with <a href="/routine/basename"><code>.basename</code></a> changed by calling <a href="/type/Str#method_succ"><code>Str.succ</code></a> on it.</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo/file02.txt</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">succ</span>.<span class="highlite-ROUTINE">say</span>; <span class="highlite-COMMENT"># OUTPUT: «&quot;foo/file03.txt&quot;.IO␤»</span></pre> </div> </div> <h2 id="method_open" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method open<a class="raku-anchor" title="direct link" href="#method_open">§</a></a></h2> <!-- defnmark method_open 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">open</span>(IO::Path:D: <span class="highlite-OPERATOR">*</span><span class="highlite-NAME_HASH">%opts</span>)</pre> </div> </div> <p>Opens the path as a file; the named options control the mode, and are the same as the <a href="/routine/open">open</a> function accepts.</p> <h2 id="method_pred" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method pred<a class="raku-anchor" title="direct link" href="#method_pred">§</a></a></h2> <!-- defnmark method_pred 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">pred</span>(IO::Path:D: <span class="highlite-KEYWORD">--&gt;</span> IO::Path:D)</pre> </div> </div> <p>Returns a new <code>IO::Path</code> constructed from the invocant, with <a href="/routine/basename"><code>.basename</code></a> changed by calling <a href="/type/Str#method_pred"><code>Str.pred</code></a> on it.</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo/file02.txt</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">pred</span>.<span class="highlite-ROUTINE">say</span>; <span class="highlite-COMMENT"># OUTPUT: «&quot;foo/file01.txt&quot;.IO␤»</span></pre> </div> </div> <h2 id="method_watch" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method watch<a class="raku-anchor" title="direct link" href="#method_watch">§</a></a></h2> <!-- defnmark method_watch 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">watch</span>(IO::Path:D: <span class="highlite-KEYWORD">--&gt;</span> Supply:D)</pre> </div> </div> <p>Equivalent to calling <a href="/type/IO/Notification#method_watch-path">IO::Notification.watch-path</a> with the invocant as the argument.</p> <h2 id="method_is-absolute" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method is-absolute<a class="raku-anchor" title="direct link" href="#method_is-absolute">§</a></a></h2> <!-- defnmark method_is-absolute 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">is-absolute</span>(IO::Path:D: <span class="highlite-KEYWORD">--&gt;</span> <span class="highlite-TYPE">Bool</span>)</pre> </div> </div> <p>Returns <code>True</code> if the path is an absolute path, and <code>False</code> otherwise.</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">/foo</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">is-absolute</span>.<span class="highlite-ROUTINE">say</span>; <span class="highlite-COMMENT"># OUTPUT: «True␤» </span><span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">bars</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">is-absolute</span>.<span class="highlite-ROUTINE">say</span>; <span class="highlite-COMMENT"># OUTPUT: «False␤»</span></pre> </div> </div> <p>Note that on Windows a path that starts with a slash or backslash is still considered absolute even if no volume was given, as it is absolute for that particular volume:</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-TYPE">IO::Path::Win32</span>.<span class="highlite-ROUTINE">new</span>(<span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">/foo</span><span class="highlite-STRING_DELIMITER">&quot;</span> ).<span class="highlite-ROUTINE">is-absolute</span>.<span class="highlite-ROUTINE">say</span>; <span class="highlite-COMMENT"># OUTPUT: «True␤» </span><span class="highlite-TYPE">IO::Path::Win32</span>.<span class="highlite-ROUTINE">new</span>(<span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">C:/foo</span><span class="highlite-STRING_DELIMITER">&quot;</span>).<span class="highlite-ROUTINE">is-absolute</span>.<span class="highlite-ROUTINE">say</span>; <span class="highlite-COMMENT"># OUTPUT: «True␤» </span><span class="highlite-TYPE">IO::Path::Win32</span>.<span class="highlite-ROUTINE">new</span>(<span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">C:foo</span><span class="highlite-STRING_DELIMITER">&quot;</span> ).<span class="highlite-ROUTINE">is-absolute</span>.<span class="highlite-ROUTINE">say</span>; <span class="highlite-COMMENT"># OUTPUT: «False␤»</span></pre> </div> </div> <h2 id="method_is-relative" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method is-relative<a class="raku-anchor" title="direct link" href="#method_is-relative">§</a></a></h2> <!-- defnmark method_is-relative 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">is-relative</span>(IO::Path:D: <span class="highlite-KEYWORD">--&gt;</span> <span class="highlite-TYPE">Bool</span>)</pre> </div> </div> <p>Returns <code>True</code> if the path is a relative path, and <code>False</code> otherwise. Windows caveats for <a href="/type/IO/Path#method_is-absolute"><code>.is-absolute</code></a> apply.</p> <h2 id="method_absolute" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method absolute<a class="raku-anchor" title="direct link" href="#method_absolute">§</a></a></h2> <!-- defnmark method_absolute 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">multi</span> <span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">absolute</span>(IO::Path:D: <span class="highlite-KEYWORD">--&gt;</span> <span class="highlite-TYPE">Str</span>) <span class="highlite-KEYWORD">multi</span> <span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">absolute</span>(IO::Path:D: <span class="highlite-NAME_SCALAR">$base</span> <span class="highlite-KEYWORD">--&gt;</span> <span class="highlite-TYPE">Str</span>)</pre> </div> </div> <p>Returns a new <a href="/type/Str"><code>Str</code></a> object that is an absolute path. If the invocant is not already an absolute path, it is first made absolute using <code>$base</code> as base, if it is provided, or the <code>.CWD</code> attribute the object was created with if it is not.</p> <h2 id="method_relative" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method relative<a class="raku-anchor" title="direct link" href="#method_relative">§</a></a></h2> <!-- defnmark method_relative 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">relative</span>(IO::Path:D: <span class="highlite-NAME_SCALAR">$base</span> <span class="highlite-OPERATOR">=</span> <span class="highlite-NAME_SCALAR">$*CWD</span> <span class="highlite-KEYWORD">--&gt;</span> <span class="highlite-TYPE">Str</span>)</pre> </div> </div> <p>Returns a new <a href="/type/Str"><code>Str</code></a> object with the path relative to the <code>$base</code>. If <code>$base</code> is not provided, <code>$*CWD</code> is used in its place. If the invocant is not an absolute path, it's first made to be absolute using the <code>.CWD</code> attribute the object was created with, and then is made relative to <code>$base</code>.</p> <h2 id="method_parent" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method parent<a class="raku-anchor" title="direct link" href="#method_parent">§</a></a></h2> <!-- defnmark method_parent 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">multi</span> <span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">parent</span>(IO::Path:D:) <span class="highlite-KEYWORD">multi</span> <span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">parent</span>(IO::Path:D: UInt:D <span class="highlite-NAME_SCALAR">$level</span>)</pre> </div> </div> <p>Returns the parent path of the invocant. Note that no actual filesystem access is made, so the returned parent is physical and not the logical parent of symlinked directories.</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">/etc/foo</span><span class="highlite-STRING_DELIMITER">'</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">parent</span>.<span class="highlite-ROUTINE">say</span>; <span class="highlite-COMMENT"># OUTPUT: «&quot;/etc&quot;.IO␤» </span><span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">/etc/..</span><span class="highlite-STRING_DELIMITER">'</span> .<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">parent</span>.<span class="highlite-ROUTINE">say</span>; <span class="highlite-COMMENT"># OUTPUT: «&quot;/etc&quot;.IO␤» </span><span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">/etc/../</span><span class="highlite-STRING_DELIMITER">'</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">parent</span>.<span class="highlite-ROUTINE">say</span>; <span class="highlite-COMMENT"># OUTPUT: «&quot;/etc&quot;.IO␤» </span><span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">./</span><span class="highlite-STRING_DELIMITER">'</span> .<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">parent</span>.<span class="highlite-ROUTINE">say</span>; <span class="highlite-COMMENT"># OUTPUT: «&quot;..&quot;.IO␤» </span><span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">foo</span><span class="highlite-STRING_DELIMITER">'</span> .<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">parent</span>.<span class="highlite-ROUTINE">say</span>; <span class="highlite-COMMENT"># OUTPUT: «&quot;.&quot;.IO␤» </span><span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">/</span><span class="highlite-STRING_DELIMITER">'</span> .<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">parent</span>.<span class="highlite-ROUTINE">say</span>; <span class="highlite-COMMENT"># OUTPUT: «&quot;/&quot;.IO␤» </span><span class="highlite-TYPE">IO::Path::Win32</span>.<span class="highlite-ROUTINE">new</span>(<span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">C:/</span><span class="highlite-STRING_DELIMITER">'</span>).<span class="highlite-ROUTINE">parent</span>.<span class="highlite-ROUTINE">say</span>; <span class="highlite-COMMENT"># OUTPUT: «&quot;C:/&quot;.IO␤»</span></pre> </div> </div> <p>If <code>$level</code> is specified, the call is equivalent to calling <code>.parent()</code> <code>$level</code> times:</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">/etc/foo</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">parent</span>(2) <span class="highlite-OPERATOR">eqv</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">/etc/foo</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">parent</span>.<span class="highlite-ROUTINE">parent</span>; <span class="highlite-COMMENT"># OUTPUT: «True␤» </span></pre> </div> </div> <h2 id="method_resolve" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method resolve<a class="raku-anchor" title="direct link" href="#method_resolve">§</a></a></h2> <!-- defnmark method_resolve 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">resolve</span>(IO::Path:D: <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$completely</span> <span class="highlite-KEYWORD">--&gt;</span> <span class="highlite-TYPE">IO::Path</span>)</pre> </div> </div> <p>Returns a new <code>IO::Path</code> object with all symbolic links and references to the parent directory (<code>..</code>) resolved. This means that the filesystem is examined for each directory in the path, and any symlinks found are followed.</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-COMMENT"># bar is a symlink pointing to &quot;/baz&quot; </span><span class="highlite-KEYWORD">my</span> <span class="highlite-NAME_SCALAR">$io</span> <span class="highlite-OPERATOR">=</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">foo/./bar/..</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">resolve</span>; <span class="highlite-COMMENT"># now &quot;/&quot; (the parent of &quot;/baz&quot;)</span></pre> </div> </div> <p>If <code>:$completely</code>, which defaults to <code>False</code>, is set to a true value, the method will <a href="/routine/fail"><code>fail</code></a> with <code>X::IO::Resolve</code> if it cannot completely resolve the path, otherwise, it will resolve as much as possible, and will merely perform <a href="/routine/cleanup"><code>cleanup</code></a> of the rest of the path. The last part of the path does <strong>NOT</strong> have to exist to <code>:$completely</code> resolve the path.</p><p>NOTE: Currently (April 2017) this method doesn't work correctly on all platforms, e.g. Windows, since <code>resolve</code> assumes POSIX semantics.</p> <h2 id="routine_dir" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">routine dir<a class="raku-anchor" title="direct link" href="#routine_dir">§</a></a></h2> <!-- defnmark routine_dir 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">multi</span> <span class="highlite-ROUTINE">dir</span>(<span class="highlite-OPERATOR">*</span><span class="highlite-NAME_HASH">%_</span>) <span class="highlite-KEYWORD">multi</span> <span class="highlite-ROUTINE">dir</span>(IO::Path:D <span class="highlite-NAME_SCALAR">$path</span><span class="highlite-OPERATOR">,</span> |c) <span class="highlite-KEYWORD">multi</span> <span class="highlite-ROUTINE">dir</span>(<span class="highlite-TYPE">IO</span>() <span class="highlite-NAME_SCALAR">$path</span><span class="highlite-OPERATOR">,</span> |c) <span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">dir</span>(IO::Path:D: <span class="highlite-TYPE">Mu</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$test</span> <span class="highlite-OPERATOR">=</span> <span class="highlite-NAME_SCALAR">$*SPEC</span>.<span class="highlite-ROUTINE">curupdir</span>)</pre> </div> </div> <p>Returns a lazy list of <code>IO::Path</code> objects corresponding to the entries in a directory, optionally filtered by <a href="/language/operators#infix_~~">smartmatching</a> their names <em>as strings</em> per the <code>:test</code> parameter. The order in which the filesystem returns entries determines the order of the entries/objects in the list. Objects corresponding to special directory entries <code>.</code> and <code>..</code> are not included. <code>$path</code> determines whether the objects' paths are absolute or relative.</p><p>Since the tests are performed against <a href="/type/Str"><code>Str</code></a> arguments, not <a href="/type/IO"><code>IO</code></a>, the tests are executed in the <code>$*CWD</code>, instead of the target directory. When testing against file test operators, this won't work:</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-ROUTINE">dir</span>(<span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">mydir</span><span class="highlite-STRING_DELIMITER">'</span><span class="highlite-OPERATOR">,</span> test <span class="highlite-OPERATOR">=&gt;</span> { .<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">d</span> })</pre> </div> </div> <p>while this will:</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-ROUTINE">dir</span>(<span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">mydir</span><span class="highlite-STRING_DELIMITER">'</span><span class="highlite-OPERATOR">,</span> test <span class="highlite-OPERATOR">=&gt;</span> { <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">mydir/</span><span class="highlite-NAME_SCALAR">$_</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">d</span> })</pre> </div> </div> <p><strong>NOTE:</strong> a <code>dir</code> call opens a directory for reading, which counts towards maximum per-process open files for your program. Be sure to exhaust returned <a href="/type/Seq"><code>Seq</code></a> before doing something like recursively performing more <code>dir</code> calls. You can exhaust it by assigning to an <code>@-</code>sigiled variable or simply looping over it. Note how examples below push further dirs to look through into an <a href="/type/Array"><code>Array</code></a>, rather than immediately calling <code>dir</code> on them. See also <a href="https://raku.land/zef:raku-community-modules/IO::Dir"><code>IO::Dir</code> module</a> that gives you finer control over closing dir handles.</p><p>Examples:</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-COMMENT"># To iterate over the contents of the current directory: </span><span class="highlite-KEYWORD">for</span> <span class="highlite-ROUTINE">dir</span>() <span class="highlite-KEYWORD">-&gt;</span> <span class="highlite-NAME_SCALAR">$file</span> { <span class="highlite-ROUTINE">say</span> <span class="highlite-NAME_SCALAR">$file</span>; } <span class="highlite-COMMENT"># As before, but include even '.' and '..' which are filtered out by </span><span class="highlite-COMMENT"># the default :test matcher: </span><span class="highlite-KEYWORD">for</span> <span class="highlite-ROUTINE">dir</span>(test <span class="highlite-OPERATOR">=&gt;</span> <span class="highlite-OPERATOR">*</span>) <span class="highlite-KEYWORD">-&gt;</span> <span class="highlite-NAME_SCALAR">$file</span> { <span class="highlite-ROUTINE">say</span> <span class="highlite-NAME_SCALAR">$file</span>; } <span class="highlite-COMMENT"># To get the names of all .jpg and .jpeg files in the home directory of the current user: </span><span class="highlite-KEYWORD">my</span> <span class="highlite-NAME_ARRAY">@jpegs</span> <span class="highlite-OPERATOR">=</span> <span class="highlite-NAME_SCALAR">$*HOME</span>.dir: test <span class="highlite-OPERATOR">=&gt;</span> <span class="highlite-REGEX_DELIMITER">/</span><span class="highlite-REGEX_SPECIAL">:</span><span class="highlite-REGEX_LITERAL">i</span><span class="highlite-REGEX_SPECIAL"> '</span><span class="highlite-REGEX_LITERAL">.</span><span class="highlite-REGEX_SPECIAL">' </span><span class="highlite-REGEX_LITERAL">jpe</span><span class="highlite-REGEX_SPECIAL">?</span><span class="highlite-REGEX_LITERAL">g</span><span class="highlite-REGEX_SPECIAL"> $</span><span class="highlite-REGEX_DELIMITER">/</span>;</pre> </div> </div> <p>An example program that lists all files and directories recursively:</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">sub</span> <span class="highlite-ROUTINE">MAIN</span>(<span class="highlite-NAME_SCALAR">$dir</span> <span class="highlite-OPERATOR">=</span> <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">.</span><span class="highlite-STRING_DELIMITER">'</span>) { <span class="highlite-KEYWORD">my</span> <span class="highlite-NAME_ARRAY">@todo</span> <span class="highlite-OPERATOR">=</span> <span class="highlite-NAME_SCALAR">$dir</span>.<span class="highlite-TYPE">IO</span>; <span class="highlite-KEYWORD">while</span> <span class="highlite-NAME_ARRAY">@todo</span> { <span class="highlite-KEYWORD">for</span> <span class="highlite-NAME_ARRAY">@todo</span>.<span class="highlite-ROUTINE">pop</span>.<span class="highlite-ROUTINE">dir</span> <span class="highlite-KEYWORD">-&gt;</span> <span class="highlite-NAME_SCALAR">$path</span> { <span class="highlite-ROUTINE">say</span> <span class="highlite-NAME_SCALAR">$path</span>.<span class="highlite-TYPE">Str</span>; <span class="highlite-NAME_ARRAY">@todo</span>.push: <span class="highlite-NAME_SCALAR">$path</span> <span class="highlite-KEYWORD">if</span> <span class="highlite-NAME_SCALAR">$path</span>.<span class="highlite-ROUTINE">d</span>; } } }</pre> </div> </div> <p>A lazy way to find the first three files ending in &quot;.raku&quot; recursively starting from the current directory:</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">my</span> <span class="highlite-NAME_ARRAY">@stack</span> <span class="highlite-OPERATOR">=</span> <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">.</span><span class="highlite-STRING_DELIMITER">'</span>.<span class="highlite-TYPE">IO</span>; <span class="highlite-KEYWORD">my</span> <span class="highlite-NAME_SCALAR">$raku-files</span> <span class="highlite-OPERATOR">=</span> <span class="highlite-KEYWORD">gather</span> <span class="highlite-KEYWORD">while</span> <span class="highlite-NAME_ARRAY">@stack</span> { <span class="highlite-KEYWORD">with</span> <span class="highlite-NAME_ARRAY">@stack</span>.<span class="highlite-ROUTINE">pop</span> { <span class="highlite-KEYWORD">when</span> :d { <span class="highlite-NAME_ARRAY">@stack</span>.append: .<span class="highlite-ROUTINE">dir</span> } .<span class="highlite-ROUTINE">take</span> <span class="highlite-KEYWORD">when</span> .<span class="highlite-ROUTINE">extension</span>.<span class="highlite-ROUTINE">lc</span> <span class="highlite-OPERATOR">eq</span> <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">raku</span><span class="highlite-STRING_DELIMITER">'</span> } } .<span class="highlite-ROUTINE">put</span> <span class="highlite-KEYWORD">for</span> <span class="highlite-NAME_SCALAR">$raku-files</span>[^3]; </pre> </div> </div> <h2 id="File_test_operators" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">File test operators<a class="raku-anchor" title="direct link" href="#File_test_operators">§</a></a></h2> <p>For most file tests, you can do a smartmatch <code>~~</code> or you can call a method. You don't need to actually open a filehandle in the traditional way (although you can) to do a filetest. You can simply append <code>.IO</code> to the filename and smartmatch it to a test adverb. For instance, here is how to check whether a file is readable using smartmatch:</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">/path/to/file</span><span class="highlite-STRING_DELIMITER">'</span>.<span class="highlite-TYPE">IO</span> <span class="highlite-OPERATOR">~~</span> :r;</pre> </div> </div> <p>File tests include:</p> <ul class="rakudoc-item"> <li><p><code>:d</code> (<a href="/type/IO/Path#method_d">Directory</a>)</p></li> <li><p><code>:e</code> (<a href="/type/IO/Path#method_e">Exists</a>)</p></li> <li><p><code>:f</code> (<a href="/type/IO/Path#method_f">File</a>)</p></li> <li><p><code>:l</code> (<a href="/type/IO/Path#method_l">Symbolic link</a>)</p></li> <li><p><code>:r</code> (<a href="/type/IO/Path#method_r">Readable</a>)</p></li> <li><p><code>:rw</code> (<a href="/type/IO/Path#method_rw">Readable and writable</a>)</p></li> <li><p><code>:rwx</code> (<a href="/type/IO/Path#method_rwx">Readable, writable and executable</a>)</p></li> <li><p><code>:s</code> (<a href="/type/IO/Path#method_s">Size</a>)</p></li> <li><p><code>:w</code> (<a href="/type/IO/Path#method_w">Writable</a>)</p></li> <li><p><code>:x</code> (<a href="/type/IO/Path#method_x">Executable</a>)</p></li> <li><p><code>:z</code> (<a href="/type/IO/Path#method_z">Zero size</a>)</p></li> </ul> <p>These tests will not cache the results of earlier test executions.</p><p><a href="/type/Pair#method_ACCEPTS">Smartmatching on Pairs</a> can be used to perform multiple tests at once:</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-ROUTINE">say</span> :d <span class="highlite-OPERATOR">&amp;</span> :x; <span class="highlite-COMMENT"># OUTPUT: «all(d =&gt; True, x =&gt; True)␤» </span><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">/tmp</span><span class="highlite-STRING_DELIMITER">'</span>.<span class="highlite-TYPE">IO</span> <span class="highlite-OPERATOR">~~</span> :d <span class="highlite-OPERATOR">&amp;</span> :x; <span class="highlite-COMMENT"># OUTPUT: «True␤» </span><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">/</span><span class="highlite-STRING_DELIMITER">'</span>.<span class="highlite-TYPE">IO</span> <span class="highlite-OPERATOR">~~</span> :d <span class="highlite-OPERATOR">&amp;</span> :rw; <span class="highlite-COMMENT"># OUTPUT: «False␤»</span></pre> </div> </div> <p>All of the above tests can be used as methods (without the colon), though method tests may throw <a href="/type/X/IO/DoesNotExist"><code>X::IO::DoesNotExist</code></a> as documented below. Three tests only exist as methods: <a href="#method_accessed"><code>accessed</code></a>, <a href="#method_changed"><code>changed</code></a> and <a href="#method_modified"><code>modified</code></a>.</p><p>You can also perform file tests on an already opened filehandle by testing against its <a href="/type/IO/Handle#method_path"><code>.path</code></a> method. For example, given filehandle <code>$fh</code>:</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-NAME_SCALAR">$fh</span>.<span class="highlite-ROUTINE">path</span> <span class="highlite-OPERATOR">~~</span> :r; <span class="highlite-NAME_SCALAR">$fh</span>.<span class="highlite-ROUTINE">path</span>.<span class="highlite-ROUTINE">r</span>; <span class="highlite-COMMENT"># method form </span></pre> </div> </div> <h2 id="method_e" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method e<a class="raku-anchor" title="direct link" href="#method_e">§</a></a></h2> <!-- defnmark method_e 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">e</span>(IO::Path:D: <span class="highlite-KEYWORD">--&gt;</span> Bool:D)</pre> </div> </div> <p>Returns <code>True</code> if the invocant is a path that exists.</p> <h2 id="method_d" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method d<a class="raku-anchor" title="direct link" href="#method_d">§</a></a></h2> <!-- defnmark method_d 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">d</span>(IO::Path:D: <span class="highlite-KEYWORD">--&gt;</span> Bool:D)</pre> </div> </div> <p>Returns <code>True</code> if the invocant is a path that exists and is a directory. The method will <a href="/routine/fail"><code>fail</code></a> with <a href="/type/X/IO/DoesNotExist"><code>X::IO::DoesNotExist</code></a> if the path points to a non-existent filesystem entity.</p> <h2 id="method_f" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method f<a class="raku-anchor" title="direct link" href="#method_f">§</a></a></h2> <!-- defnmark method_f 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">f</span>(IO::Path:D: <span class="highlite-KEYWORD">--&gt;</span> Bool:D)</pre> </div> </div> <p>Returns <code>True</code> if the invocant is a path that exists and is a file. The method will <a href="/routine/fail"><code>fail</code></a> with <a href="/type/X/IO/DoesNotExist"><code>X::IO::DoesNotExist</code></a> if the path points to a non-existent filesystem entity.</p> <h2 id="method_s" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method s<a class="raku-anchor" title="direct link" href="#method_s">§</a></a></h2> <!-- defnmark method_s 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">s</span>(IO::Path:D: <span class="highlite-KEYWORD">--&gt;</span> Int:D)</pre> </div> </div> <p>Returns the file size in bytes. May be called on paths that are directories, in which case the reported size is dependent on the operating system. The method will <a href="/routine/fail"><code>fail</code></a> with <a href="/type/X/IO/DoesNotExist"><code>X::IO::DoesNotExist</code></a> if the path points to a non-existent filesystem entity.</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-ROUTINE">say</span> <span class="highlite-NAME_SCALAR">$*EXECUTABLE</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-REGEX_DELIMITER">s;</span><span class="highlite-REGEX_SPECIAL"> </span><span class="highlite-COMMENT"># OUTPUT: «467␤»</span><span class="highlite-REGEX_DELIMITER"></span><span class="highlite-STRING"></span><span class="highlite-REGEX_DELIMITER"></span></pre> </div> </div> <h2 id="method_l" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method l<a class="raku-anchor" title="direct link" href="#method_l">§</a></a></h2> <!-- defnmark method_l 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">l</span>(IO::Path:D: <span class="highlite-KEYWORD">--&gt;</span> Bool:D)</pre> </div> </div> <p>Returns <code>True</code> if the invocant is a path that exists and is a symlink. The method will <a href="/routine/fail"><code>fail</code></a> with <a href="/type/X/IO/DoesNotExist"><code>X::IO::DoesNotExist</code></a> if the path points to a non-existent filesystem entity.</p> <h2 id="method_r" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method r<a class="raku-anchor" title="direct link" href="#method_r">§</a></a></h2> <!-- defnmark method_r 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">r</span>(IO::Path:D: <span class="highlite-KEYWORD">--&gt;</span> Bool:D)</pre> </div> </div> <p>Returns <code>True</code> if the invocant is a path that exists and is accessible. The method will <a href="/routine/fail"><code>fail</code></a> with <a href="/type/X/IO/DoesNotExist"><code>X::IO::DoesNotExist</code></a> if the path points to a non-existent filesystem entity.</p> <h2 id="method_w" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method w<a class="raku-anchor" title="direct link" href="#method_w">§</a></a></h2> <!-- defnmark method_w 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">w</span>(IO::Path:D: <span class="highlite-KEYWORD">--&gt;</span> Bool:D)</pre> </div> </div> <p>Returns <code>True</code> if the invocant is a path that exists and is writable. The method will <a href="/routine/fail"><code>fail</code></a> with <a href="/type/X/IO/DoesNotExist"><code>X::IO::DoesNotExist</code></a> if the path points to a non-existent filesystem entity.</p> <h2 id="method_rw" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method rw<a class="raku-anchor" title="direct link" href="#method_rw">§</a></a></h2> <!-- defnmark method_rw 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-KEYWORD">rw</span>(IO::Path:D: <span class="highlite-KEYWORD">--&gt;</span> Bool:D)</pre> </div> </div> <p>Returns <code>True</code> if the invocant is a path that exists and is readable and writable. The method will <a href="/routine/fail"><code>fail</code></a> with <a href="/type/X/IO/DoesNotExist"><code>X::IO::DoesNotExist</code></a> if the path points to a non-existent filesystem entity.</p> <h2 id="method_x" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method x<a class="raku-anchor" title="direct link" href="#method_x">§</a></a></h2> <!-- defnmark method_x 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-OPERATOR">x</span>(IO::Path:D: <span class="highlite-KEYWORD">--&gt;</span> Bool:D)</pre> </div> </div> <p>Returns <code>True</code> if the invocant is a path that exists and is executable. The method will <a href="/routine/fail"><code>fail</code></a> with <a href="/type/X/IO/DoesNotExist"><code>X::IO::DoesNotExist</code></a> if the path points to a non-existent filesystem entity.</p><p><strong>NOTE:</strong> If the file is a script (an executable text file and not a native executable), and the file has <em>only</em> executable permissions and <em>no</em> read permissions, this method will return <code>True</code> but trying to execute will fail. That is a limitation of the operating system.</p> <h2 id="method_rwx" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method rwx<a class="raku-anchor" title="direct link" href="#method_rwx">§</a></a></h2> <!-- defnmark method_rwx 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">rwx</span>(IO::Path:D: <span class="highlite-KEYWORD">--&gt;</span> Bool:D)</pre> </div> </div> <p>Returns <code>True</code> if the invocant is a path that exists and is executable, readable, and writable. The method will <a href="/routine/fail"><code>fail</code></a> with <a href="/type/X/IO/DoesNotExist"><code>X::IO::DoesNotExist</code></a> if the path points to a non-existent filesystem entity.</p> <h2 id="method_z" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method z<a class="raku-anchor" title="direct link" href="#method_z">§</a></a></h2> <!-- defnmark method_z 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">z</span>(IO::Path:D: <span class="highlite-KEYWORD">--&gt;</span> Bool:D)</pre> </div> </div> <p>Returns <code>True</code> if the invocant is a path that exists and has size of <code>0</code>. May be called on paths that are directories, in which case the reported file size (and thus the result of this method) is dependent on the operating system. The method will <a href="/routine/fail"><code>fail</code></a> with <a href="/type/X/IO/DoesNotExist"><code>X::IO::DoesNotExist</code></a> if the path points to a non-existent filesystem entity.</p> <h2 id="method_sibling" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method sibling<a class="raku-anchor" title="direct link" href="#method_sibling">§</a></a></h2> <!-- defnmark method_sibling 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">sibling</span>(IO::Path:D: <span class="highlite-TYPE">Str</span>() <span class="highlite-NAME_SCALAR">$sibling</span> <span class="highlite-KEYWORD">--&gt;</span> IO::Path:D)</pre> </div> </div> <p>Allows to reference a sibling file or directory. Returns a new <code>IO::Path</code> based on the invocant, with the <a href="/type/IO/Path#method_basename"><code>.basename</code></a> changed to <code>$sibling</code>. The <code>$sibling</code> is allowed to be a multi-part path fragment; see also <a href="/type/IO/Path#method_add"><code>.add</code></a>.</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">.bashrc</span><span class="highlite-STRING_DELIMITER">'</span>.<span class="highlite-TYPE">IO</span>.sibling: <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">.bash_aliases</span><span class="highlite-STRING_DELIMITER">'</span>; <span class="highlite-COMMENT"># OUTPUT: «.bash_aliases&quot;.IO␤» </span><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">/home/camelia/.bashrc</span><span class="highlite-STRING_DELIMITER">'</span>.<span class="highlite-TYPE">IO</span>.sibling: <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">.bash_aliases</span><span class="highlite-STRING_DELIMITER">'</span>; <span class="highlite-COMMENT"># OUTPUT: «/home/camelia/.bash_aliases&quot;.IO␤» </span> <span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">/foo/</span><span class="highlite-STRING_DELIMITER">'</span> .<span class="highlite-TYPE">IO</span>.sibling: <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">bar</span><span class="highlite-STRING_DELIMITER">'</span>; <span class="highlite-COMMENT"># OUTPUT: «/bar&quot;.IO␤» </span><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">/foo/.</span><span class="highlite-STRING_DELIMITER">'</span>.<span class="highlite-TYPE">IO</span>.sibling: <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">bar</span><span class="highlite-STRING_DELIMITER">'</span>; <span class="highlite-COMMENT"># OUTPUT: «/foo/bar&quot;.IO␤»</span></pre> </div> </div> <h2 id="method_words" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method words<a class="raku-anchor" title="direct link" href="#method_words">§</a></a></h2> <!-- defnmark method_words 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">words</span>(IO::Path:D: <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$chomp</span> <span class="highlite-OPERATOR">=</span> <span class="highlite-TYPE">True</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$enc</span> <span class="highlite-OPERATOR">=</span> <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">utf8</span><span class="highlite-STRING_DELIMITER">'</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$nl-in</span> <span class="highlite-OPERATOR">=</span> [<span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-ESCAPE">\x</span><span class="highlite-STRING">0A</span><span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-OPERATOR">,</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-ESCAPE">\r</span><span class="highlite-ESCAPE">\n</span><span class="highlite-STRING_DELIMITER">&quot;</span>]<span class="highlite-OPERATOR">,</span> |c <span class="highlite-KEYWORD">--&gt;</span> Seq:D)</pre> </div> </div> <p>Opens the invocant and returns its <a href="/type/IO/Handle#routine_words">words</a>.</p><p>The behavior is equivalent to <a href="/routine/open">opening</a> the file specified by the invocant, forwarding the <code>:$chomp</code>, <code>:$enc</code>, and <code>:$nl-in</code> arguments to <a href="/type/IO/Handle#method_open"><code>IO::Handle.open</code></a>, then calling <a href="/type/IO/Handle#routine_words"><code>IO::Handle.words</code></a> on that handle, forwarding any of the remaining arguments to that method, and returning the resultant <a href="/type/Seq"><code>Seq</code></a>.</p><p><strong>NOTE:</strong> words are lazily read. The handle used under the hood is not closed until the returned <a href="/type/Seq"><code>Seq</code></a> is <a href="/language/glossary#Reify">fully reified</a>, and this could lead to leaking open filehandles. It is possible to avoid leaking open filehandles using the <a href="/type/IO/Handle#routine_words"><code>$limit</code> argument</a> to cut down the <a href="/type/Seq"><code>Seq</code></a> of words to be generated.</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">my</span> <span class="highlite-NAME_HASH">%dict</span> <span class="highlite-OPERATOR">:=</span> <span class="highlite-ROUTINE">bag</span> <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">my-file.txt</span><span class="highlite-STRING_DELIMITER">'</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">words</span>; <span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">Most common words: </span><span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-OPERATOR">,</span> <span class="highlite-NAME_HASH">%dict</span>.<span class="highlite-ROUTINE">sort</span>(<span class="highlite-OPERATOR">-</span>*.<span class="highlite-ROUTINE">value</span>).head: 5; </pre> </div> </div> <h2 id="method_lines" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method lines<a class="raku-anchor" title="direct link" href="#method_lines">§</a></a></h2> <!-- defnmark method_lines 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">lines</span>(IO::Path:D: <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$chomp</span> <span class="highlite-OPERATOR">=</span> <span class="highlite-TYPE">True</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$enc</span> <span class="highlite-OPERATOR">=</span> <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">utf8</span><span class="highlite-STRING_DELIMITER">'</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$nl-in</span> <span class="highlite-OPERATOR">=</span> [<span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-ESCAPE">\x</span><span class="highlite-STRING">0A</span><span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-OPERATOR">,</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-ESCAPE">\r</span><span class="highlite-ESCAPE">\n</span><span class="highlite-STRING_DELIMITER">&quot;</span>]<span class="highlite-OPERATOR">,</span> |c <span class="highlite-KEYWORD">--&gt;</span> Seq:D)</pre> </div> </div> <p>Opens the invocant and returns its <a href="/type/IO/Handle#routine_lines">lines</a>.</p><p>The behavior is equivalent to <a href="/routine/open">opening</a> the file specified by the invocant, forwarding the <code>:$chomp</code>, <code>:$enc</code>, and <code>:$nl-in</code> arguments to <a href="/type/IO/Handle#method_open"><code>IO::Handle.open</code></a>, then calling <a href="/type/IO/Handle#routine_lines"><code>IO::Handle.lines</code></a> on that handle, forwarding any of the remaining arguments to that method, and returning the resultant <a href="/type/Seq"><code>Seq</code></a>.</p><p><strong>NOTE:</strong> the lines are ready lazily and the handle used under the hood won't get closed until the returned <a href="/type/Seq"><code>Seq</code></a> is <a href="/language/glossary#Reify">fully reified</a>, so ensure it is, or you'll be leaking open filehandles. (TIP: use the <a href="/type/IO/Handle#routine_lines"><code>$limit</code> argument</a>)</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">The file contains </span><span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-OPERATOR">,</span> <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">50GB-file</span><span class="highlite-STRING_DELIMITER">'</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">lines</span>.<span class="highlite-ROUTINE">grep</span>(<span class="highlite-OPERATOR">*</span>.contains: <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">Raku</span><span class="highlite-STRING_DELIMITER">'</span>).<span class="highlite-ROUTINE">elems</span><span class="highlite-OPERATOR">,</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING"> lines that mention Raku</span><span class="highlite-STRING_DELIMITER">&quot;</span>; <span class="highlite-COMMENT"># OUTPUT: «The file contains 72 lines that mention Raku␤» </span></pre> </div> </div> <h2 id="routine_slurp" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">routine slurp<a class="raku-anchor" title="direct link" href="#routine_slurp">§</a></a></h2> <!-- defnmark routine_slurp 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">multi</span> <span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">slurp</span>(IO::Path:D: <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$bin</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$enc</span>)</pre> </div> </div> <p>Read all of the file's content and return it as either <a href="/type/Buf"><code>Buf</code></a>, if <code>:$bin</code> is <code>True</code>, or if not, as <a href="/type/Str"><code>Str</code></a> decoded with <code>:$enc</code> encoding, which defaults to <code>utf8</code>. File will be closed afterwards. See <a href="/routine/open"><code>&amp;open</code></a> for valid values for <code>:$enc</code>.</p> <h2 id="method_spurt" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method spurt<a class="raku-anchor" title="direct link" href="#method_spurt">§</a></a></h2> <!-- defnmark method_spurt 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">spurt</span>(IO::Path:D: <span class="highlite-NAME_SCALAR">$data</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$enc</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$append</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$createonly</span>)</pre> </div> </div> <p>Opens the path for writing, and writes all of the <code>$data</code> into it. File will be closed afterwards. Will <a href="/routine/fail"><code>fail</code></a> if it cannot succeed for any reason. The <code>$data</code> can be any <a href="/type/Cool"><code>Cool</code></a> type or any <a href="/type/Blob"><code>Blob</code></a> type. Arguments are as follows:</p> <ul class="rakudoc-item"> <li><p><code>:$enc</code> — character encoding of the data. Takes same values as <code>:$enc</code> in <a href="/routine/open"><code>IO::Handle.open</code></a>. Defaults to <code>utf8</code>. Ignored if <code>$data</code> is a <a href="/type/Blob"><code>Blob</code></a>.</p></li> <li><p><code>:$append</code> — open the file in <code>append</code> mode, preserving existing contents, and appending data to the end of the file.</p></li> <li><p><code>:$createonly</code> — <a href="/routine/fail"><code>fail</code></a> if the file already exists.</p></li> </ul> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">spurt</span>(IO::Path:D:)</pre> </div> </div> <p>As of the 2020.12 release of the Rakudo compiler, it is also possible to call the <code>spurt</code> method without any data. This will either create an empty file, or will truncate any existing file at the given path.</p> <h2 id="method_chdir" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method chdir<a class="raku-anchor" title="direct link" href="#method_chdir">§</a></a></h2> <!-- defnmark method_chdir 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">multi</span> <span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">chdir</span>(IO::Path:D: <span class="highlite-TYPE">IO</span> <span class="highlite-NAME_SCALAR">$path</span><span class="highlite-OPERATOR">,</span> |c) <span class="highlite-KEYWORD">multi</span> <span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">chdir</span>(IO::Path:D: <span class="highlite-TYPE">Str</span>() <span class="highlite-NAME_SCALAR">$path</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$d</span> <span class="highlite-OPERATOR">=</span> <span class="highlite-TYPE">True</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$r</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$w</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$x</span>)</pre> </div> </div> <p>Contrary to the name, the <code>.chdir</code> method does not change any directories, but merely concatenates the given <code>$path</code> to the invocant and returns the resultant <code>IO::Path</code>. Optional file tests can be performed by providing <code>:d</code>, <code>:r</code>, <code>:w</code>, or <code>:x</code> <a href="/type/Bool"><code>Bool</code></a> named arguments; when set to <code>True</code>, they'll perform <a href="/routine/d"><code>.d</code></a>, <a href="/routine/r"><code>.r</code></a>, <a href="/routine/w"><code>.w</code></a>, and <a href="/routine/x"><code>.x</code></a> tests respectively. By default, only <code>:d</code> is set to <code>True</code>.</p> <h2 id="method_mkdir" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method mkdir<a class="raku-anchor" title="direct link" href="#method_mkdir">§</a></a></h2> <!-- defnmark method_mkdir 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">mkdir</span>(IO::Path:D: <span class="highlite-TYPE">Int</span>() <span class="highlite-NAME_SCALAR">$mode</span> <span class="highlite-OPERATOR">=</span> 0o777 <span class="highlite-KEYWORD">--&gt;</span> IO::Path:D)</pre> </div> </div> <p>Creates a new directory, including its parent directories, as needed (similar to *nix utility <code>mkdir</code> with <code>-p</code> option). That is, <code>mkdir &quot;foo/bar/ber/meow&quot;</code> will create <code>foo</code>, <code>foo/bar</code>, and <code>foo/bar/ber</code> directories as well if they do not exist.</p><p>Returns the <code>IO::Path</code> object pointing to the newly created directory on success; <a href="/routine/fail">fails</a> with <a href="/type/X/IO/Mkdir"><code>X::IO::Mkdir</code></a> if directory cannot be created.</p><p>See also <a href="/routine/mode"><code>mode</code></a> for explanation and valid values for <code>$mode</code>.</p> <h2 id="routine_rmdir" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">routine rmdir<a class="raku-anchor" title="direct link" href="#routine_rmdir">§</a></a></h2> <!-- defnmark routine_rmdir 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">sub</span> <span class="highlite-ROUTINE">rmdir</span>(<span class="highlite-OPERATOR">*</span><span class="highlite-NAME_ARRAY">@dirs</span> <span class="highlite-KEYWORD">--&gt;</span> List:D) <span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">rmdir</span>(IO::Path:D: <span class="highlite-KEYWORD">--&gt;</span> <span class="highlite-TYPE">True</span>)</pre> </div> </div> <p>Remove the invocant, or in sub form, all of the provided directories in the given list, which can contain any <a href="/type/Cool"><code>Cool</code></a> object. Only works on empty directories.</p><p>Method form returns <code>True</code> on success and returns a <a href="/type/Failure"><code>Failure</code></a> of type <a href="/type/X/IO/Rmdir"><code>X::IO::Rmdir</code></a> if the directory cannot be removed (e.g. the directory is not empty, or the path is not a directory). Subroutine form returns a list of directories that were successfully deleted.</p><p>To delete non-empty directory, see <a href="https://github.com/labster/p6-file-directory-tree">rmtree in <code>File::Directory::Tree</code> module</a>.</p> <h2 id="method_chmod" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method chmod<a class="raku-anchor" title="direct link" href="#method_chmod">§</a></a></h2> <!-- defnmark method_chmod 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">chmod</span>(IO::Path:D: <span class="highlite-TYPE">Int</span>() <span class="highlite-NAME_SCALAR">$mode</span> <span class="highlite-KEYWORD">--&gt;</span> <span class="highlite-TYPE">Bool</span>)</pre> </div> </div> <p>Changes the POSIX permissions of a file or directory to <code>$mode</code>. Returns <code>True</code> on success; on failure, <a href="/routine/fail">fails</a> with <a href="/type/X/IO/Chmod"><code>X::IO::Chmod</code></a>.</p><p>The mode is expected as an integer following the <a href="https://en.wikipedia.org/wiki/File_system_permissions#Numeric_notation">standard numeric notation</a>, and is best written as an octal number:</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">myfile</span><span class="highlite-STRING_DELIMITER">'</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">chmod</span>(0o444); <span class="highlite-COMMENT"># make a file read-only </span><span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">somedir</span><span class="highlite-STRING_DELIMITER">'</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">chmod</span>(0o777); <span class="highlite-COMMENT"># set 0777 permissions on a directory </span></pre> </div> </div> <p>Make sure you <em>don't</em> accidentally pass the intended octal digits as a decimal number (or string containing a decimal number):</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">myfile</span><span class="highlite-STRING_DELIMITER">'</span>.<span class="highlite-TYPE">IO</span>.chmod: <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">0444</span><span class="highlite-STRING_DELIMITER">'</span>; <span class="highlite-COMMENT"># BAD!!! (interpreted as mode 0o674) </span><span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">myfile</span><span class="highlite-STRING_DELIMITER">'</span>.<span class="highlite-TYPE">IO</span>.chmod: <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">0o444</span><span class="highlite-STRING_DELIMITER">'</span>; <span class="highlite-COMMENT"># OK (an octal in a string) </span><span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">myfile</span><span class="highlite-STRING_DELIMITER">'</span>.<span class="highlite-TYPE">IO</span>.chmod: 0o444; <span class="highlite-COMMENT"># Also OK (an octal literal) </span></pre> </div> </div> <h2 id="routine_rename" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">routine rename<a class="raku-anchor" title="direct link" href="#routine_rename">§</a></a></h2> <!-- defnmark routine_rename 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">rename</span>(IO::Path:D: <span class="highlite-TYPE">IO</span>() <span class="highlite-NAME_SCALAR">$to</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$createonly</span> <span class="highlite-OPERATOR">=</span> <span class="highlite-TYPE">False</span> <span class="highlite-KEYWORD">--&gt;</span> Bool:D) <span class="highlite-KEYWORD">sub</span> <span class="highlite-ROUTINE">rename</span>(<span class="highlite-TYPE">IO</span>() <span class="highlite-NAME_SCALAR">$from</span><span class="highlite-OPERATOR">,</span> <span class="highlite-TYPE">IO</span>() <span class="highlite-NAME_SCALAR">$to</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$createonly</span> <span class="highlite-OPERATOR">=</span> <span class="highlite-TYPE">False</span> <span class="highlite-KEYWORD">--&gt;</span> Bool:D)</pre> </div> </div> <p>Renames a file or directory. Returns <code>True</code> on success; <a href="/routine/fail">fails</a> with <a href="/type/X/IO/Rename"><code>X::IO::Rename</code></a> if <code>:$createonly</code> is <code>True</code> and the <code>$to</code> path already exists or if the operation failed for some other reason.</p><p><strong>Note:</strong> some renames will always fail, such as when the new name is on a different storage device. See also: <a href="/routine/move"><code>move</code></a>.</p> <h2 id="routine_copy" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">routine copy<a class="raku-anchor" title="direct link" href="#routine_copy">§</a></a></h2> <!-- defnmark routine_copy 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">copy</span>(IO::Path:D: <span class="highlite-TYPE">IO</span>() <span class="highlite-NAME_SCALAR">$to</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$createonly</span> <span class="highlite-KEYWORD">--&gt;</span> Bool:D) <span class="highlite-KEYWORD">sub</span> <span class="highlite-ROUTINE">copy</span>(<span class="highlite-TYPE">IO</span>() <span class="highlite-NAME_SCALAR">$from</span><span class="highlite-OPERATOR">,</span> <span class="highlite-TYPE">IO</span>() <span class="highlite-NAME_SCALAR">$to</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$createonly</span> <span class="highlite-KEYWORD">--&gt;</span> Bool:D)</pre> </div> </div> <p>Copies a file. Returns <code>True</code> on success; <a href="/routine/fail">fails</a> with <a href="/type/X/IO/Copy"><code>X::IO::Copy</code></a> if <code>:$createonly</code> is <code>True</code> and the <code>$to</code> path already exists or if the operation failed for some other reason, such as when <code>$to</code> and <code>$from</code> are the same file.</p> <h2 id="routine_move" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">routine move<a class="raku-anchor" title="direct link" href="#routine_move">§</a></a></h2> <!-- defnmark routine_move 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">move</span>(IO::Path:D: <span class="highlite-TYPE">IO</span>() <span class="highlite-NAME_SCALAR">$to</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$createonly</span> <span class="highlite-KEYWORD">--&gt;</span> Bool:D) <span class="highlite-KEYWORD">sub</span> <span class="highlite-ROUTINE">move</span>(<span class="highlite-TYPE">IO</span>() <span class="highlite-NAME_SCALAR">$from</span><span class="highlite-OPERATOR">,</span> <span class="highlite-TYPE">IO</span>() <span class="highlite-NAME_SCALAR">$to</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$createonly</span> <span class="highlite-KEYWORD">--&gt;</span> Bool:D)</pre> </div> </div> <p>Copies a file and then removes the original. If removal fails, it's possible to end up with two copies of the file. Returns <code>True</code> on success; <a href="/routine/fail">fails</a> with <a href="/type/X/IO/Move"><code>X::IO::Move</code></a> if <code>:$createonly</code> is <code>True</code> and the <code>$to</code> path already exists or if the operation failed for some other reason, such as when <code>$to</code> and <code>$from</code> are the same file.</p><p>To avoid copying, you can use <a href="/routine/rename"><code>rename</code></a>, if the files are on the same storage device. It also works with directories, while <code>move</code> does not.</p> <h2 id="method_Numeric" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method Numeric<a class="raku-anchor" title="direct link" href="#method_Numeric">§</a></a></h2> <!-- defnmark method_Numeric 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-TYPE">Numeric</span>(IO::Path:D: <span class="highlite-KEYWORD">--&gt;</span> Numeric:D)</pre> </div> </div> <p>Coerces <a href="/routine/basename"><code>.basename</code></a> to <a href="/type/Numeric"><code>Numeric</code></a>. <a href="/routine/fail">Fails</a> with <a href="/type/X/Str/Numeric"><code>X::Str::Numeric</code></a> if base name is not numerical.</p> <h2 id="method_Int" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method Int<a class="raku-anchor" title="direct link" href="#method_Int">§</a></a></h2> <!-- defnmark method_Int 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-TYPE">Int</span>(IO::Path:D: <span class="highlite-KEYWORD">--&gt;</span> Int:D)</pre> </div> </div> <p>Coerces <a href="/routine/basename"><code>.basename</code></a> to <a href="/type/Int"><code>Int</code></a>. <a href="/routine/fail">Fails</a> with <a href="/type/X/Str/Numeric"><code>X::Str::Numeric</code></a> if base name is not numerical.</p> <h2 id="routine_symlink" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">routine symlink<a class="raku-anchor" title="direct link" href="#routine_symlink">§</a></a></h2> <!-- defnmark routine_symlink 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">symlink</span>(IO::Path:D <span class="highlite-NAME_SCALAR">$target:</span> <span class="highlite-TYPE">IO</span>() <span class="highlite-NAME_SCALAR">$link</span><span class="highlite-OPERATOR">,</span> <span class="highlite-TYPE">Bool</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$absolute</span> <span class="highlite-OPERATOR">=</span> <span class="highlite-TYPE">True</span> <span class="highlite-KEYWORD">--&gt;</span> Bool:D) <span class="highlite-KEYWORD">sub</span> <span class="highlite-ROUTINE">symlink</span>( <span class="highlite-TYPE">IO</span>() <span class="highlite-NAME_SCALAR">$target</span><span class="highlite-OPERATOR">,</span> <span class="highlite-TYPE">IO</span>() <span class="highlite-NAME_SCALAR">$link</span><span class="highlite-OPERATOR">,</span> <span class="highlite-TYPE">Bool</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$absolute</span> <span class="highlite-OPERATOR">=</span> <span class="highlite-TYPE">True</span> <span class="highlite-KEYWORD">--&gt;</span> Bool:D)</pre> </div> </div> <p>Create a new <em>symbolic</em> link <code>$link</code> to existing <code>$target</code>. Returns <code>True</code> on success; <a href="/routine/fail">fails</a> with <a href="/type/X/IO/Symlink"><code>X::IO::Symlink</code></a> if the symbolic link could not be created. If <code>$target</code> does not exist, creates a dangling symbolic link.</p><p><code>symlink</code> creates a symbolic link using an absolute path by default. To create a relative symlink set the <code>absolute</code> parameter to <code>False</code> e.g. <code>:!absolute</code>. This flag was introduced in Rakudo version 2020.11.</p><p>To create a hard link, see <a href="/routine/link"><code>link</code></a>.</p><p><strong>Note:</strong> on Windows, creation of symbolic links may require escalated privileges.</p> <h2 id="routine_link" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">routine link<a class="raku-anchor" title="direct link" href="#routine_link">§</a></a></h2> <!-- defnmark routine_link 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">link</span>(IO::Path:D <span class="highlite-NAME_SCALAR">$target:</span> <span class="highlite-TYPE">IO</span>() <span class="highlite-NAME_SCALAR">$link</span> <span class="highlite-KEYWORD">--&gt;</span> Bool:D) <span class="highlite-KEYWORD">sub</span> <span class="highlite-ROUTINE">link</span>( <span class="highlite-TYPE">IO</span>() <span class="highlite-NAME_SCALAR">$target</span><span class="highlite-OPERATOR">,</span> <span class="highlite-TYPE">IO</span>() <span class="highlite-NAME_SCALAR">$link</span> <span class="highlite-KEYWORD">--&gt;</span> Bool:D)</pre> </div> </div> <p>Create a new <em>hard</em> link <code>$link</code> to existing <code>$target</code>. Returns <code>True</code> on success; <a href="/routine/fail">fails</a> with <a href="/type/X/IO/Link"><code>X::IO::Link</code></a> if the hard link could not be created. To create a symbolic link, see <a href="/routine/symlink"><code>symlink</code></a>.</p> <h2 id="routine_unlink" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">routine unlink<a class="raku-anchor" title="direct link" href="#routine_unlink">§</a></a></h2> <!-- defnmark routine_unlink 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">unlink</span>(IO::Path:D: <span class="highlite-KEYWORD">--&gt;</span> <span class="highlite-TYPE">True</span>) <span class="highlite-KEYWORD">sub</span> <span class="highlite-ROUTINE">unlink</span>(<span class="highlite-OPERATOR">*</span><span class="highlite-NAME_ARRAY">@filenames</span> <span class="highlite-KEYWORD">--&gt;</span> List:D)</pre> </div> </div> <p>Delete all specified ordinary files, links, or symbolic links for which there are privileges to do so. See <a href="/routine/rmdir">rmdir</a> to delete directories.</p><p>The subroutine form returns the names of all the files in the list, excluding those for which the filesystem raised some error; since trying to delete a file that does not exist does not raise any error at that level, this list will include the names of the files in the list that do not exist.</p><p>The method form returns <code>True</code> on success, or <a href="/routine/fail">fails</a> with <a href="/type/X/IO/Unlink"><code>X::IO::Unlink</code></a> if the operation could not be completed. If the file to be deleted does not exist, the routine treats it as success.</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">foo.txt</span><span class="highlite-STRING_DELIMITER">'</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">open</span>(:w).<span class="highlite-ROUTINE">close</span>; <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">bar</span><span class="highlite-STRING_DELIMITER">'</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">mkdir</span>; <span class="highlite-ROUTINE">say</span> <span class="highlite-ROUTINE">unlink</span> &lt;foo.txt bar not-there.txt&gt;; <span class="highlite-COMMENT"># OUTPUT: «[foo.txt not-there.txt]␤» </span><span class="highlite-COMMENT"># `bar` is not in output because it failed to delete (it's a directory) </span><span class="highlite-COMMENT"># `not-there.txt` is present. It never existed, so that's deemed a success. </span> <span class="highlite-COMMENT"># Method form `fail`s: </span><span class="highlite-ROUTINE">say</span> .<span class="highlite-ROUTINE">exception</span>.<span class="highlite-ROUTINE">message</span> <span class="highlite-KEYWORD">without</span> <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">bar</span><span class="highlite-STRING_DELIMITER">'</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">unlink</span>; <span class="highlite-COMMENT"># OUTPUT: «Failed to remove the file […] illegal operation on a directory␤» </span></pre> </div> </div> <h2 id="routine_chown" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">routine chown<a class="raku-anchor" title="direct link" href="#routine_chown">§</a></a></h2> <!-- defnmark routine_chown 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> chown(IO::Path:D: <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$uid</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$gid</span> <span class="highlite-KEYWORD">--&gt;</span> <span class="highlite-TYPE">True</span>) <span class="highlite-KEYWORD">sub</span> chown(<span class="highlite-OPERATOR">*</span><span class="highlite-NAME_ARRAY">@filenames</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$uid</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$gid</span> <span class="highlite-KEYWORD">--&gt;</span> List:D)</pre> </div> </div> <p>Available as of release 2022.12 of the Rakudo compiler.</p><p>Change the owner and/or group of all specified ordinary files, links, or symbolic links for which there are privileges to do so.</p><p>The subroutine form returns the names of all the files in the list, excluding those for which the filesystem raised some error.</p><p>The method form returns <code>True</code> on success, or <a href="/routine/fail">fails</a> with <a href="/type/X/IO/Chown"><code>X::IO::Chown</code></a> if the operation could not be completed.</p><p>Note that this operation only makes sense on operating systems with the concept of an &quot;owner&quot; and a &quot;group&quot;, which is typically on Unix-like systems.</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">success</span><span class="highlite-STRING_DELIMITER">&quot;</span> <span class="highlite-KEYWORD">if</span> <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">foo.txt</span><span class="highlite-STRING_DELIMITER">'</span>.<span class="highlite-TYPE">IO</span>.chown(:uid(137)); </pre> </div> </div> <h2 id="method_IO" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method IO<a class="raku-anchor" title="direct link" href="#method_IO">§</a></a></h2> <!-- defnmark method_IO 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-TYPE">IO</span>(IO::Path:D: <span class="highlite-KEYWORD">--&gt;</span> <span class="highlite-TYPE">IO::Path</span>)</pre> </div> </div> <p>Returns the invocant.</p> <h2 id="method_SPEC" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method SPEC<a class="raku-anchor" title="direct link" href="#method_SPEC">§</a></a></h2> <!-- defnmark method_SPEC 2 --> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">SPEC</span>(IO::Path:D: <span class="highlite-KEYWORD">--&gt;</span> <span class="highlite-TYPE">IO::Spec</span>)</pre> </div> </div> <p>Returns the <a href="/type/IO/Spec"><code>IO::Spec</code></a> object that was (implicitly) specified at object creation time.</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">my</span> <span class="highlite-NAME_SCALAR">$io</span> <span class="highlite-OPERATOR">=</span> <span class="highlite-TYPE">IO::Path</span>.<span class="highlite-ROUTINE">new</span>(<span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">/bin/bash</span><span class="highlite-STRING_DELIMITER">&quot;</span>); <span class="highlite-ROUTINE">say</span> <span class="highlite-NAME_SCALAR">$io</span>.<span class="highlite-ROUTINE">SPEC</span>; <span class="highlite-COMMENT"># OUTPUT: «(Unix)␤» </span><span class="highlite-ROUTINE">say</span> <span class="highlite-NAME_SCALAR">$io</span>.<span class="highlite-ROUTINE">SPEC</span>.<span class="highlite-ROUTINE">dir-sep</span>; <span class="highlite-COMMENT"># OUTPUT: «/␤»</span></pre> </div> </div> <h1 id="File_timestamp_retrieval" class="raku-h1"><a href="#class_IO::Path" title="go to top of document">File timestamp retrieval<a class="raku-anchor" title="direct link" href="#File_timestamp_retrieval">§</a></a></h1> <p>There are also 3 methods for fetching the 3 timestamps of a file (inode), on Operating Systems where these are available:</p> <h2 id="method_created" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method created<a class="raku-anchor" title="direct link" href="#method_created">§</a></a></h2> <!-- defnmark method_created 2 --> <p>Returns an <a href="/type/Instant"><code>Instant</code></a> object indicating when the file was created.</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">path/to/file</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.created; <span class="highlite-COMMENT"># Instant:1424089165 </span><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">path/to/file</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.created.<span class="highlite-TYPE">DateTime</span>; <span class="highlite-COMMENT"># 2015-02-16T12:18:50Z </span></pre> </div> </div> <p>Available as of the 2022.12 release of the Rakudo compiler.</p> <h2 id="method_modified" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method modified<a class="raku-anchor" title="direct link" href="#method_modified">§</a></a></h2> <!-- defnmark method_modified 2 --> <p>Returns an <a href="/type/Instant"><code>Instant</code></a> object indicating when the content of the file was last modified. Compare with <a href="/routine/changed">changed</a>.</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">path/to/file</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">modified</span>; <span class="highlite-COMMENT"># Instant:1424089165 </span><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">path/to/file</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">modified</span>.<span class="highlite-TYPE">DateTime</span>; <span class="highlite-COMMENT"># 2015-02-16T12:18:50Z </span></pre> </div> </div> <h2 id="method_accessed" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method accessed<a class="raku-anchor" title="direct link" href="#method_accessed">§</a></a></h2> <!-- defnmark method_accessed 2 --> <p>Return an <a href="/type/Instant"><code>Instant</code></a> object representing the timestamp when the file was last accessed. <strong>Note:</strong> depending on how the filesystem was mounted, the last accessed time may not update on <em>each access</em> to the file, but only on the first access after modifications.</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">path/to/file</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">accessed</span>; <span class="highlite-COMMENT"># Instant:1424353577 </span><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">path/to/file</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">accessed</span>.<span class="highlite-TYPE">DateTime</span>; <span class="highlite-COMMENT"># 2015-02-19T13:45:42Z </span></pre> </div> </div> <h2 id="method_changed" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method changed<a class="raku-anchor" title="direct link" href="#method_changed">§</a></a></h2> <!-- defnmark method_changed 2 --> <p>Returns an <a href="/type/Instant"><code>Instant</code></a> object indicating the metadata of the file or directory was last changed (e.g. permissions, or files created/deleted in directory). Compare with <a href="/routine/modified">modified</a>.</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">path/to/file</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">changed</span>; <span class="highlite-COMMENT"># Instant:1424089165 </span><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">path/to/file</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">changed</span>.<span class="highlite-TYPE">DateTime</span>; <span class="highlite-COMMENT"># 2015-02-16T12:18:50Z </span></pre> </div> </div> <h1 id="File_permissions_retrieval" class="raku-h1"><a href="#class_IO::Path" title="go to top of document">File permissions retrieval<a class="raku-anchor" title="direct link" href="#File_permissions_retrieval">§</a></a></h1> <h2 id="method_mode" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method mode<a class="raku-anchor" title="direct link" href="#method_mode">§</a></a></h2> <!-- defnmark method_mode 2 --> <p>Return an <a href="/type/IntStr"><code>IntStr</code></a> object representing the POSIX permissions of a file. The <a href="/type/Str"><code>Str</code></a> part of the result is the octal representation of the file permission, like the form accepted by the <code>chmod(1)</code> utility.</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-ROUTINE">say</span> <span class="highlite-OPERATOR">~</span><span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">path/to/file</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">mode</span>; <span class="highlite-COMMENT"># e.g. '0644' </span><span class="highlite-ROUTINE">say</span> <span class="highlite-OPERATOR">+</span><span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">path/to/file</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">mode</span>; <span class="highlite-COMMENT"># e.g. 420, where sprintf('%04o', 420) eq '0644' </span></pre> </div> </div> <p>The result of this can be used in the other methods that take a mode as an argument.</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">path/to/file1</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">chmod</span>(<span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">path/to/file2</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.<span class="highlite-ROUTINE">mode</span>); <span class="highlite-COMMENT"># will change the </span> <span class="highlite-COMMENT"># permissions of file1 </span> <span class="highlite-COMMENT"># to be the same as file2 </span></pre> </div> </div> <h1 id="Other_informational_methods" class="raku-h1"><a href="#class_IO::Path" title="go to top of document">Other informational methods<a class="raku-anchor" title="direct link" href="#Other_informational_methods">§</a></a></h1> <h2 id="method_user" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method user<a class="raku-anchor" title="direct link" href="#method_user">§</a></a></h2> <!-- defnmark method_user 2 --> <p>Available as of the 2021.04 Rakudo compiler release.</p><p>The <code>user</code> method returns the numeric user ID (aka &quot;uid&quot;) of the path on operating systems that support such a notion.</p> <h2 id="method_group" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method group<a class="raku-anchor" title="direct link" href="#method_group">§</a></a></h2> <!-- defnmark method_group 2 --> <p>Available as of the 2021.04 Rakudo compiler release.</p><p>The <code>group</code> method returns the numeric group ID (aka &quot;gid&quot;) of the path on operating systems that support such a notion.</p> <h2 id="method_dir-with-entries" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method dir-with-entries<a class="raku-anchor" title="direct link" href="#method_dir-with-entries">§</a></a></h2> <!-- defnmark method_dir-with-entries 2 --> <p>Available as of the 2022.04 Rakudo compiler release.</p><p>Returns a <a href="/type/Bool"><code>Bool</code></a> indicating whether the path is a directory with <strong>any</strong> entries in it. Throws an exception if the path is not a directory, or the path doesn't exist.</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">'</span><span class="highlite-NAME_SCALAR">$_'</span><span class="highlite-STRING"> has entries</span><span class="highlite-STRING_DELIMITER">&quot;</span> <span class="highlite-KEYWORD">if</span> .<span class="highlite-ROUTINE">d</span> <span class="highlite-OPERATOR">&amp;&amp;</span> .dir-with-entries <span class="highlite-KEYWORD">given</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">path/to/dir</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>; </pre> </div> </div> <h2 id="method_inode" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method inode<a class="raku-anchor" title="direct link" href="#method_inode">§</a></a></h2> <!-- defnmark method_inode 2 --> <p>Available as of the 2022.07 Rakudo compiler release.</p><p>Returns an <a href="/type/Int"><code>Int</code></a> object representing the inode of the path on the filesystem (if the filesystem supports such a notion).</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">path/to/file</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.inode; <span class="highlite-COMMENT"># e.g. 9003678 </span></pre> </div> </div> <h2 id="method_dev" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method dev<a class="raku-anchor" title="direct link" href="#method_dev">§</a></a></h2> <!-- defnmark method_dev 2 --> <p>Available as of the 2022.07 Rakudo compiler release.</p><p>Returns an <a href="/type/Int"><code>Int</code></a> object representing the <code>dev</code> (the <code>st_dev</code> field of the POSIX <code>stat</code> function) of the path on the filesystem (if the filesystem supports such a notion).</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">path/to/file</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.dev; <span class="highlite-COMMENT"># e.g. 16777233 </span></pre> </div> </div> <h2 id="method_devtype" class="raku-h2"><a href="#class_IO::Path" title="go to top of document">method devtype<a class="raku-anchor" title="direct link" href="#method_devtype">§</a></a></h2> <!-- defnmark method_devtype 2 --> <p>Available as of the 2022.07 Rakudo compiler release.</p><p>Returns an <a href="/type/Int"><code>Int</code></a> object representing the <code>devtype</code> (the <code>st_rdev</code> field of the POSIX <code>stat</code> function) of the path on the filesystem (if the filesystem supports such a notion).</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-ROUTINE">say</span> <span class="highlite-STRING_DELIMITER">&quot;</span><span class="highlite-STRING">path/to/file</span><span class="highlite-STRING_DELIMITER">&quot;</span>.<span class="highlite-TYPE">IO</span>.devtype; <span class="highlite-COMMENT"># e.g. 0 </span></pre> </div> </div> </div></div></section> </div> </div> </div> <footer class="footer main-footer"> <div class="container px-4"> <nav class="level"> <div class="level-left"> <div class="level-item"> <a href="/about">About</a> </div> <div class="level-item"> <a id="toggle-theme">Toggle theme</a> </div> <div class="level-item" title="3ed988e34 2024-08-04"> <a>Commit</a> </div> </div> <div class="level-right"> <div class="level-item"> <a href="/license">License</a> </div> </div> </nav> </div> </footer> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10