Files
Nim/osfiles.html
github-actions[bot] ef3d9e7b38 Deploy to GitHub pages
2025-12-28 15:55:52 +00:00

426 lines
44 KiB
HTML

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- This file is generated by Nim. -->
<html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en" data-theme="auto">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>std/private/osfiles</title>
<!-- Google fonts -->
<link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
<link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
<!-- Favicon -->
<link rel="shortcut icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAUAAAAF////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAIAAABbAAAAlQAAAKIAAACbAAAAmwAAAKIAAACVAAAAWwAAAAL///8A////AP///wD///8A////AAAAABQAAADAAAAAYwAAAA3///8A////AP///wD///8AAAAADQAAAGMAAADAAAAAFP///wD///8A////AP///wAAAACdAAAAOv///wD///8A////AP///wD///8A////AP///wD///8AAAAAOgAAAJ3///8A////AP///wAAAAAnAAAAcP///wAAAAAoAAAASv///wD///8A////AP///wAAAABKAAAAKP///wAAAABwAAAAJ////wD///8AAAAAgQAAABwAAACIAAAAkAAAAJMAAACtAAAAFQAAABUAAACtAAAAkwAAAJAAAACIAAAAHAAAAIH///8A////AAAAAKQAAACrAAAAaP///wD///8AAAAARQAAANIAAADSAAAARf///wD///8AAAAAaAAAAKsAAACk////AAAAADMAAACcAAAAnQAAABj///8A////AP///wAAAAAYAAAAGP///wD///8A////AAAAABgAAACdAAAAnAAAADMAAAB1AAAAwwAAAP8AAADpAAAAsQAAAE4AAAAb////AP///wAAAAAbAAAATgAAALEAAADpAAAA/wAAAMMAAAB1AAAAtwAAAOkAAAD/AAAA/wAAAP8AAADvAAAA3gAAAN4AAADeAAAA3gAAAO8AAAD/AAAA/wAAAP8AAADpAAAAtwAAAGUAAAA/AAAA3wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAADfAAAAPwAAAGX///8A////AAAAAEgAAADtAAAAvwAAAL0AAADGAAAA7wAAAO8AAADGAAAAvQAAAL8AAADtAAAASP///wD///8A////AP///wD///8AAAAAO////wD///8A////AAAAAIcAAACH////AP///wD///8AAAAAO////wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A//8AAP//AAD4HwAA7/cAAN/7AAD//wAAoYUAAJ55AACf+QAAh+EAAAAAAADAAwAA4AcAAP5/AAD//wAA//8AAA=="/>
<link rel="icon" type="image/png" sizes="32x32" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4QQQEwksSS9ZWwAAAk1JREFUWMPtll2ITVEUx39nn/O7Y5qR8f05wtCUUr6ZIS++8pEnkZInPImneaCQ5METNdOkeFBKUhMPRIkHKfEuUZSUlGlKPN2TrgfncpvmnntnmlEyq1Z7t89/rf9a6+y99oZxGZf/XeIq61EdtgKXgdXA0xrYAvBjOIF1AI9zvjcC74BSpndrJPkBWDScTF8Aa4E3wDlgHbASaANmVqlcCnwHvgDvgVfAJ+AikAAvgfVZwLnSVZHZaOuKoQi3ZOMi4NkYkpe1p4J7A8BpYAD49hfIy/oqG0+hLomiKP2L5L+1ubn5115S+3OAn4EnwBlgMzCjyt6ZAnQCJ4A7wOs88iRJHvw50HoujuPBoCKwHWiosy8MdfZnAdcHk8dxXFJ3VQbQlCTJvRBCGdRbD4M6uc5glpY3eAihpN5S5w12diSEcCCEcKUO4ljdr15T76ur1FDDLIQQ3qv71EdDOe3Kxj3leRXyk+pxdWnFWod6Wt2bY3de3aSuUHcPBVimHs7mK9WrmeOF6lR1o9qnzskh2ar2qm1qizpfXaPeVGdlmGN5pb09qMxz1Xb1kLqgzn1RyH7JUXW52lr5e/Kqi9qpto7V1atuUzfnARrV7jEib1T76gG2qxdGmXyiekkt1GswPTtek0aBfJp6YySGBfWg2tPQ0FAYgf1stUfdmdcjarbYJEniKIq6gY/Aw+zWHAC+p2labGpqiorFYgGYCEzN7oQdQClN07O1/EfDyGgC0ALMBdYAi4FyK+4H3gLPsxfR1zRNi+NP7nH5J+QntnXe5B5mpfQAAAAASUVORK5CYII=">
<!-- CSS -->
<link rel="stylesheet" type="text/css" href="nimdoc.out.css?v=2.3.1">
<!-- JS -->
<script type="text/javascript" src="dochack.js?v=2.3.1"></script>
</head>
<body>
<div class="document" id="documentId">
<div class="container">
<h1 class="title">std/private/osfiles</h1>
<div class="row">
<div class="three columns">
<div class="theme-select-wrapper">
<label for="theme-select">Theme:&nbsp;</label>
<select id="theme-select" onchange="setTheme(this.value)">
<option value="auto">🌗 Match OS</option>
<option value="dark">🌑 Dark</option>
<option value="light">🌕 Light</option>
</select>
</div>
<div id="global-links">
<ul class="simple-boot">
<li><a href="manual.html">Manual</a></li>
<li><a href="lib.html">Standard library</a></li>
<li> <a id="indexLink" href="theindex.html">Index</a></li>
<li><a href="compiler/theindex.html">Compiler docs</a></li>
<li><a href="https://nim-lang.github.io/fusion/theindex.html">Fusion docs</a></li>
<li><a href="https://nim-lang.github.io/Nim/">devel</a>, <a href="https://nim-lang.org/documentation.html">stable</a></li>
</ul>
</div>
<div id="searchInputDiv">
Search: <input type="search" id="searchInput"
oninput="search()" />
</div>
<ul class="simple simple-toc" id="toc-list">
<li>
<a class="reference reference-toplevel" href="#6" id="56">Imports</a>
</li>
<li>
<details open>
<summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
<ul class="simple simple-toc-section">
<li><a class="reference" href="#CopyFlag" title="CopyFlag = enum
cfSymlinkAsIs, ## Copy symlinks as symlinks
cfSymlinkFollow, ## Copy the files symlinks point to
cfSymlinkIgnore ## Ignore symlinks">CopyFlag</a></li>
<li><a class="reference" href="#FilePermission" title="FilePermission = enum
fpUserExec, ## execute access for the file owner
fpUserWrite, ## write access for the file owner
fpUserRead, ## read access for the file owner
fpGroupExec, ## execute access for the group
fpGroupWrite, ## write access for the group
fpGroupRead, ## read access for the group
fpOthersExec, ## execute access for others
fpOthersWrite, ## write access for others
fpOthersRead ## read access for others">FilePermission</a></li>
</ul>
</details>
</li>
<li>
<details open>
<summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
<ul class="simple simple-toc-section">
<ul class="simple nested-toc-section">copyFile
<li><a class="reference" href="#copyFile%2Cstring%2Cstring%2Cint" title="copyFile(source, dest: string; options = {cfSymlinkFollow}; bufferSize = 16384)">copyFile(source, dest: string; options = {cfSymlinkFollow}; bufferSize = 16384)</a></li>
</ul>
<ul class="simple nested-toc-section">copyFileToDir
<li><a class="reference" href="#copyFileToDir%2Cstring%2Cstring%2Cint" title="copyFileToDir(source, dir: string; options = {cfSymlinkFollow};
bufferSize = 16384)">copyFileToDir(source, dir: string; options = {cfSymlinkFollow};
bufferSize = 16384)</a></li>
</ul>
<ul class="simple nested-toc-section">copyFileWithPermissions
<li><a class="reference" href="#copyFileWithPermissions%2Cstring%2Cstring" title="copyFileWithPermissions(source, dest: string; ignorePermissionErrors = true;
options = {cfSymlinkFollow})">copyFileWithPermissions(source, dest: string; ignorePermissionErrors = true;
options = {cfSymlinkFollow})</a></li>
</ul>
<ul class="simple nested-toc-section">getFilePermissions
<li><a class="reference" href="#getFilePermissions%2Cstring" title="getFilePermissions(filename: string): set[FilePermission]">getFilePermissions(filename: string): set[FilePermission]</a></li>
</ul>
<ul class="simple nested-toc-section">moveFile
<li><a class="reference" href="#moveFile%2Cstring%2Cstring" title="moveFile(source, dest: string)">moveFile(source, dest: string)</a></li>
</ul>
<ul class="simple nested-toc-section">removeFile
<li><a class="reference" href="#removeFile%2Cstring" title="removeFile(file: string)">removeFile(file: string)</a></li>
</ul>
<ul class="simple nested-toc-section">setFilePermissions
<li><a class="reference" href="#setFilePermissions%2Cstring%2Cset%5BFilePermission%5D" title="setFilePermissions(filename: string; permissions: set[FilePermission];
followSymlinks = true)">setFilePermissions(filename: string; permissions: set[FilePermission];
followSymlinks = true)</a></li>
</ul>
<ul class="simple nested-toc-section">tryRemoveFile
<li><a class="reference" href="#tryRemoveFile%2Cstring" title="tryRemoveFile(file: string): bool">tryRemoveFile(file: string): bool</a></li>
</ul>
</ul>
</details>
</li>
<li>
<a class="reference reference-toplevel" href="#19" id="69">Exports</a>
</li>
</ul>
</div>
<div class="nine columns" id="content">
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/private/osfiles.nim#L1" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/private/osfiles.nim#L1" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
<div id="tocRoot"></div>
<p class="module-desc"></p>
<div class="section" id="6">
<h1><a class="toc-backref" href="#6">Imports</a></h1>
<dl class="item">
<a class="reference external" href="since.html">since</a>, <a class="reference external" href="oserrors.html">oserrors</a>, <a class="reference external" href="oscommon.html">oscommon</a>, <a class="reference external" href="ospaths2.html">ospaths2</a>, <a class="reference external" href="ossymlinks.html">ossymlinks</a>, <a class="reference external" href="syncio.html">syncio</a>, <a class="reference external" href="assertions.html">assertions</a>, <a class="reference external" href="widestrs.html">widestrs</a>, <a class="reference external" href="posix.html">posix</a>, <a class="reference external" href="times.html">times</a>
</dl>
</div>
<div class="section" id="7">
<h1><a class="toc-backref" href="#7">Types</a></h1>
<dl class="item">
<div id="CopyFlag">
<dt><pre><a href="osfiles.html#CopyFlag"><span class="Identifier">CopyFlag</span></a> <span class="Other">=</span> <span class="Keyword">enum</span>
<span class="Identifier">cfSymlinkAsIs</span><span class="Other">,</span> <span class="Comment">## Copy symlinks as symlinks</span>
<span class="Identifier">cfSymlinkFollow</span><span class="Other">,</span> <span class="Comment">## Copy the files symlinks point to</span>
<span class="Identifier">cfSymlinkIgnore</span> <span class="Comment">## Ignore symlinks</span></pre></dt>
<dd>
Copy options.
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/private/osfiles.nim#L167" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/private/osfiles.nim#L167" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
<div id="FilePermission">
<dt><pre><a href="osfiles.html#FilePermission"><span class="Identifier">FilePermission</span></a> <span class="Other">=</span> <span class="Keyword">enum</span>
<span class="Identifier">fpUserExec</span><span class="Other">,</span> <span class="Comment">## execute access for the file owner</span>
<span class="Identifier">fpUserWrite</span><span class="Other">,</span> <span class="Comment">## write access for the file owner</span>
<span class="Identifier">fpUserRead</span><span class="Other">,</span> <span class="Comment">## read access for the file owner</span>
<span class="Identifier">fpGroupExec</span><span class="Other">,</span> <span class="Comment">## execute access for the group</span>
<span class="Identifier">fpGroupWrite</span><span class="Other">,</span> <span class="Comment">## write access for the group</span>
<span class="Identifier">fpGroupRead</span><span class="Other">,</span> <span class="Comment">## read access for the group</span>
<span class="Identifier">fpOthersExec</span><span class="Other">,</span> <span class="Comment">## execute access for others</span>
<span class="Identifier">fpOthersWrite</span><span class="Other">,</span> <span class="Comment">## write access for others</span>
<span class="Identifier">fpOthersRead</span> <span class="Comment">## read access for others</span></pre></dt>
<dd>
<p>File access permission, modelled after UNIX.</p>
<p>See also:</p>
<ul class="simple"><li><a class="reference internal nimdoc" title="proc getFilePermissions(filename: string): set[FilePermission]" href="#getFilePermissions,string">getFilePermissions</a></li>
<li><a class="reference internal nimdoc" title="proc setFilePermissions(filename: string; permissions: set[FilePermission];
followSymlinks = true)" href="#setFilePermissions,string,set[FilePermission]">setFilePermissions</a></li>
<li><a class="reference external" href="./os.html#FileInfo">os: FileInfo object</a></li>
</ul>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/private/osfiles.nim#L42" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/private/osfiles.nim#L42" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</dl>
</div>
<div class="section" id="12">
<h1><a class="toc-backref" href="#12">Procs</a></h1>
<dl class="item">
<div id="copyFile-procs-all">
<div id="copyFile,string,string,int">
<dt><pre><span class="Keyword">proc</span> <a href="#copyFile%2Cstring%2Cstring%2Cint"><span class="Identifier">copyFile</span></a><span class="Other">(</span><span class="Identifier">source</span><span class="Other">,</span> <span class="Identifier">dest</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">options</span> <span class="Other">=</span> <span class="Other">{</span><span class="Identifier">cfSymlinkFollow</span><span class="Other">}</span><span class="Other">;</span>
<span class="Identifier">bufferSize</span> <span class="Other">=</span> <span class="DecNumber">16384</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;nos$1&quot;</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span>
<a href="oscommon.html#ReadDirEffect"><span class="Identifier">ReadDirEffect</span></a><span class="Other">,</span> <a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">,</span> <a href="exceptions.html#WriteIOEffect"><span class="Identifier">WriteIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">,</span> <span class="Identifier">IOError</span><span class="Other">]</span><span class="Other">,</span>
<span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
<p>Copies a file from <tt class="docutils literal"><span class="pre"><span class="Identifier">source</span></span></tt> to <tt class="docutils literal"><span class="pre"><span class="Identifier">dest</span></span></tt>, where <tt class="docutils literal"><span class="pre"><span class="Identifier">dest</span><span class="Operator">.</span><span class="Identifier">parentDir</span></span></tt> must exist.</p>
<p>On non-Windows OSes, <tt class="docutils literal"><span class="pre"><span class="Identifier">options</span></span></tt> specify the way file is copied; by default, if <tt class="docutils literal"><span class="pre"><span class="Identifier">source</span></span></tt> is a symlink, copies the file symlink points to. <tt class="docutils literal"><span class="pre"><span class="Identifier">options</span></span></tt> is ignored on Windows: symlinks are skipped.</p>
<p>If this fails, <tt class="docutils literal"><span class="pre"><span class="Identifier">OSError</span></span></tt> is raised.</p>
<p>On the Windows platform this proc will copy the source file's attributes into dest.</p>
<p>On other platforms you need to use <a class="reference internal nimdoc" title="proc getFilePermissions(filename: string): set[FilePermission]" href="#getFilePermissions,string">getFilePermissions</a> and <a class="reference internal nimdoc" title="proc setFilePermissions(filename: string; permissions: set[FilePermission];
followSymlinks = true)" href="#setFilePermissions,string,set[FilePermission]">setFilePermissions</a> procs to copy them by hand (or use the convenience <a class="reference internal nimdoc" title="proc copyFileWithPermissions(source, dest: string; ignorePermissionErrors = true;
options = {cfSymlinkFollow})" href="#copyFileWithPermissions,string,string">copyFileWithPermissions proc</a>), otherwise <tt class="docutils literal"><span class="pre"><span class="Identifier">dest</span></span></tt> will inherit the default permissions of a newly created file for the user.</p>
<p>If <tt class="docutils literal"><span class="pre"><span class="Identifier">dest</span></span></tt> already exists, the file attributes will be preserved and the content overwritten.</p>
<p>On OSX, <tt class="docutils literal"><span class="pre"><span class="Identifier">copyfile</span></span></tt> C api will be used (available since OSX 10.5) unless <tt class="docutils literal"><span class="pre"><span class="Operator">-</span><span class="Identifier">d</span><span class="Punctuation">:</span><span class="Identifier">nimLegacyCopyFile</span></span></tt> is used.</p>
<p><tt class="docutils literal"><span class="pre"><span class="Identifier">copyFile</span></span></tt> allows to specify <tt class="docutils literal"><span class="pre"><span class="Identifier">bufferSize</span></span></tt> to improve I/O performance.</p>
<p>See also:</p>
<ul class="simple"><li><a class="reference internal nimdoc" title="enum CopyFlag" href="#CopyFlag">CopyFlag enum</a></li>
<li><a class="reference external" href="./osdirs.html#copyDir,string,string">osdirs: copyDir proc</a></li>
<li><a class="reference internal nimdoc" title="proc copyFileWithPermissions(source, dest: string; ignorePermissionErrors = true;
options = {cfSymlinkFollow})" href="#copyFileWithPermissions,string,string">copyFileWithPermissions proc</a></li>
<li><a class="reference internal nimdoc" title="proc tryRemoveFile(file: string): bool" href="#tryRemoveFile,string">tryRemoveFile proc</a></li>
<li><a class="reference internal nimdoc" title="proc removeFile(file: string)" href="#removeFile,string">removeFile proc</a></li>
<li><a class="reference internal nimdoc" title="proc moveFile(source, dest: string)" href="#moveFile,string,string">moveFile proc</a></li>
</ul>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/private/osfiles.nim#L174" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/private/osfiles.nim#L174" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</div>
<div id="copyFileToDir-procs-all">
<div id="copyFileToDir,string,string,int">
<dt><pre><span class="Keyword">proc</span> <a href="#copyFileToDir%2Cstring%2Cstring%2Cint"><span class="Identifier">copyFileToDir</span></a><span class="Other">(</span><span class="Identifier">source</span><span class="Other">,</span> <span class="Identifier">dir</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">options</span> <span class="Other">=</span> <span class="Other">{</span><span class="Identifier">cfSymlinkFollow</span><span class="Other">}</span><span class="Other">;</span>
<span class="Identifier">bufferSize</span> <span class="Other">=</span> <span class="DecNumber">16384</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ValueError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">,</span> <span class="Identifier">IOError</span><span class="Other">]</span><span class="Other">,</span>
<span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ReadDirEffect</span><span class="Other">,</span> <span class="Identifier">ReadIOEffect</span><span class="Other">,</span> <span class="Identifier">WriteIOEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
<p>Copies a file <tt class="docutils literal"><span class="pre"><span class="Identifier">source</span></span></tt> into directory <tt class="docutils literal"><span class="pre"><span class="Identifier">dir</span></span></tt>, which must exist.</p>
<p>On non-Windows OSes, <tt class="docutils literal"><span class="pre"><span class="Identifier">options</span></span></tt> specify the way file is copied; by default, if <tt class="docutils literal"><span class="pre"><span class="Identifier">source</span></span></tt> is a symlink, copies the file symlink points to. <tt class="docutils literal"><span class="pre"><span class="Identifier">options</span></span></tt> is ignored on Windows: symlinks are skipped.</p>
<p><tt class="docutils literal"><span class="pre"><span class="Identifier">copyFileToDir</span></span></tt> allows to specify <tt class="docutils literal"><span class="pre"><span class="Identifier">bufferSize</span></span></tt> to improve I/O performance.</p>
<p>See also:</p>
<ul class="simple"><li><a class="reference internal nimdoc" title="enum CopyFlag" href="#CopyFlag">CopyFlag enum</a></li>
<li><a class="reference internal nimdoc" title="proc copyFile(source, dest: string; options = {cfSymlinkFollow}; bufferSize = 16384)" href="#copyFile,string,string,int">copyFile proc</a></li>
</ul>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/private/osfiles.nim#L268" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/private/osfiles.nim#L268" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</div>
<div id="copyFileWithPermissions-procs-all">
<div id="copyFileWithPermissions,string,string">
<dt><pre><span class="Keyword">proc</span> <a href="#copyFileWithPermissions%2Cstring%2Cstring"><span class="Identifier">copyFileWithPermissions</span></a><span class="Other">(</span><span class="Identifier">source</span><span class="Other">,</span> <span class="Identifier">dest</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span>
<span class="Identifier">ignorePermissionErrors</span> <span class="Other">=</span> <span class="Identifier">true</span><span class="Other">;</span>
<span class="Identifier">options</span> <span class="Other">=</span> <span class="Other">{</span><span class="Identifier">cfSymlinkFollow</span><span class="Other">}</span><span class="Other">)</span> {.
<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">,</span> <span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span>
<span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ReadDirEffect</span><span class="Other">,</span> <span class="Identifier">ReadIOEffect</span><span class="Other">,</span> <span class="Identifier">WriteIOEffect</span><span class="Other">,</span> <span class="Identifier">WriteDirEffect</span><span class="Other">]</span><span class="Other">,</span>
<span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
<p>Copies a file from <tt class="docutils literal"><span class="pre"><span class="Identifier">source</span></span></tt> to <tt class="docutils literal"><span class="pre"><span class="Identifier">dest</span></span></tt> preserving file permissions.</p>
<p>On non-Windows OSes, <tt class="docutils literal"><span class="pre"><span class="Identifier">options</span></span></tt> specify the way file is copied; by default, if <tt class="docutils literal"><span class="pre"><span class="Identifier">source</span></span></tt> is a symlink, copies the file symlink points to. <tt class="docutils literal"><span class="pre"><span class="Identifier">options</span></span></tt> is ignored on Windows: symlinks are skipped.</p>
<p>This is a wrapper proc around <a class="reference internal nimdoc" title="proc copyFile(source, dest: string; options = {cfSymlinkFollow}; bufferSize = 16384)" href="#copyFile,string,string,int">copyFile</a>, <a class="reference internal nimdoc" title="proc getFilePermissions(filename: string): set[FilePermission]" href="#getFilePermissions,string">getFilePermissions</a> and <a class="reference internal nimdoc" title="proc setFilePermissions(filename: string; permissions: set[FilePermission];
followSymlinks = true)" href="#setFilePermissions,string,set[FilePermission]">setFilePermissions</a> procs on non-Windows platforms.</p>
<p>On Windows this proc is just a wrapper for <a class="reference internal nimdoc" title="proc copyFile(source, dest: string; options = {cfSymlinkFollow}; bufferSize = 16384)" href="#copyFile,string,string,int">copyFile proc</a> since that proc already copies attributes.</p>
<p>On non-Windows systems permissions are copied after the file itself has been copied, which won't happen atomically and could lead to a race condition. If <tt class="docutils literal"><span class="pre"><span class="Identifier">ignorePermissionErrors</span></span></tt> is true (default), errors while reading/setting file attributes will be ignored, otherwise will raise <tt class="docutils literal"><span class="pre"><span class="Identifier">OSError</span></span></tt>.</p>
<p>See also:</p>
<ul class="simple"><li><a class="reference internal nimdoc" title="enum CopyFlag" href="#CopyFlag">CopyFlag enum</a></li>
<li><a class="reference internal nimdoc" title="proc copyFile(source, dest: string; options = {cfSymlinkFollow}; bufferSize = 16384)" href="#copyFile,string,string,int">copyFile proc</a></li>
<li><a class="reference external" href="./osdirs.html#copyDir,string,string">osdirs: copyDir proc</a></li>
<li><a class="reference internal nimdoc" title="proc tryRemoveFile(file: string): bool" href="#tryRemoveFile,string">tryRemoveFile proc</a></li>
<li><a class="reference internal nimdoc" title="proc removeFile(file: string)" href="#removeFile,string">removeFile proc</a></li>
<li><a class="reference internal nimdoc" title="proc moveFile(source, dest: string)" href="#moveFile,string,string">moveFile proc</a></li>
<li><a class="reference external" href="./osdirs.html#copyDirWithPermissions,string,string">osdirs: copyDirWithPermissions proc</a></li>
</ul>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/private/osfiles.nim#L286" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/private/osfiles.nim#L286" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</div>
<div id="getFilePermissions-procs-all">
<div id="getFilePermissions,string">
<dt><pre><span class="Keyword">proc</span> <a href="#getFilePermissions%2Cstring"><span class="Identifier">getFilePermissions</span></a><span class="Other">(</span><span class="Identifier">filename</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#set"><span class="Identifier">set</span></a><span class="Other">[</span><a href="osfiles.html#FilePermission"><span class="Identifier">FilePermission</span></a><span class="Other">]</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span>
<span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;nos$1&quot;</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="oscommon.html#ReadDirEffect"><span class="Identifier">ReadDirEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
<p>Retrieves file permissions for <tt class="docutils literal"><span class="pre"><span class="Identifier">filename</span></span></tt>.</p>
<p><tt class="docutils literal"><span class="pre"><span class="Identifier">OSError</span></span></tt> is raised in case of an error. On Windows, only the <tt class="docutils literal"><span class="pre">readonly</span></tt> flag is checked, every other permission is available in any case.</p>
<p>See also:</p>
<ul class="simple"><li><a class="reference internal nimdoc" title="proc setFilePermissions(filename: string; permissions: set[FilePermission];
followSymlinks = true)" href="#setFilePermissions,string,set[FilePermission]">setFilePermissions proc</a></li>
<li><a class="reference internal nimdoc" title="enum FilePermission" href="#FilePermission">FilePermission enum</a></li>
</ul>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/private/osfiles.nim#L58" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/private/osfiles.nim#L58" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</div>
<div id="moveFile-procs-all">
<div id="moveFile,string,string">
<dt><pre><span class="Keyword">proc</span> <a href="#moveFile%2Cstring%2Cstring"><span class="Identifier">moveFile</span></a><span class="Other">(</span><span class="Identifier">source</span><span class="Other">,</span> <span class="Identifier">dest</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;nos$1&quot;</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span>
<a href="oscommon.html#ReadDirEffect"><span class="Identifier">ReadDirEffect</span></a><span class="Other">,</span> <a href="exceptions.html#ReadIOEffect"><span class="Identifier">ReadIOEffect</span></a><span class="Other">,</span> <a href="exceptions.html#WriteIOEffect"><span class="Identifier">WriteIOEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">,</span> <span class="Identifier">IOError</span><span class="Other">,</span>
<span class="Identifier">Exception</span><span class="Other">,</span> <span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
<p>Moves a file from <tt class="docutils literal"><span class="pre"><span class="Identifier">source</span></span></tt> to <tt class="docutils literal"><span class="pre"><span class="Identifier">dest</span></span></tt>.</p>
<p>Symlinks are not followed: if <tt class="docutils literal"><span class="pre"><span class="Identifier">source</span></span></tt> is a symlink, it is itself moved, not its target.</p>
<p>If this fails, <tt class="docutils literal"><span class="pre"><span class="Identifier">OSError</span></span></tt> is raised. If <tt class="docutils literal"><span class="pre"><span class="Identifier">dest</span></span></tt> already exists, it will be overwritten.</p>
<p>Can be used to <span id="rename-files_1">rename files</span>.</p>
<p>See also:</p>
<ul class="simple"><li><a class="reference external" href="./osdirs.html#moveDir,string,string">osdirs: moveDir proc</a></li>
<li><a class="reference internal nimdoc" title="proc copyFile(source, dest: string; options = {cfSymlinkFollow}; bufferSize = 16384)" href="#copyFile,string,string,int">copyFile proc</a></li>
<li><a class="reference internal nimdoc" title="proc copyFileWithPermissions(source, dest: string; ignorePermissionErrors = true;
options = {cfSymlinkFollow})" href="#copyFileWithPermissions,string,string">copyFileWithPermissions proc</a></li>
<li><a class="reference internal nimdoc" title="proc removeFile(file: string)" href="#removeFile,string">removeFile proc</a></li>
<li><a class="reference internal nimdoc" title="proc tryRemoveFile(file: string): bool" href="#tryRemoveFile,string">tryRemoveFile proc</a></li>
</ul>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/private/osfiles.nim#L385" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/private/osfiles.nim#L385" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</div>
<div id="removeFile-procs-all">
<div id="removeFile,string">
<dt><pre><span class="Keyword">proc</span> <a href="#removeFile%2Cstring"><span class="Identifier">removeFile</span></a><span class="Other">(</span><span class="Identifier">file</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;nos$1&quot;</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="oscommon.html#WriteDirEffect"><span class="Identifier">WriteDirEffect</span></a><span class="Other">]</span><span class="Other">,</span>
<span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
<p>Removes the <tt class="docutils literal"><span class="pre"><span class="Identifier">file</span></span></tt>.</p>
<p>If this fails, <tt class="docutils literal"><span class="pre"><span class="Identifier">OSError</span></span></tt> is raised. This does not fail if the file never existed in the first place.</p>
<p>On Windows, ignores the read-only attribute.</p>
<p>See also:</p>
<ul class="simple"><li><a class="reference external" href="./osdirs.html#removeDir,string">osdirs: removeDir proc</a></li>
<li><a class="reference internal nimdoc" title="proc copyFile(source, dest: string; options = {cfSymlinkFollow}; bufferSize = 16384)" href="#copyFile,string,string,int">copyFile proc</a></li>
<li><a class="reference internal nimdoc" title="proc copyFileWithPermissions(source, dest: string; ignorePermissionErrors = true;
options = {cfSymlinkFollow})" href="#copyFileWithPermissions,string,string">copyFileWithPermissions proc</a></li>
<li><a class="reference internal nimdoc" title="proc tryRemoveFile(file: string): bool" href="#tryRemoveFile,string">tryRemoveFile proc</a></li>
<li><a class="reference internal nimdoc" title="proc moveFile(source, dest: string)" href="#moveFile,string,string">moveFile proc</a></li>
</ul>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/private/osfiles.nim#L368" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/private/osfiles.nim#L368" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</div>
<div id="setFilePermissions-procs-all">
<div id="setFilePermissions,string,set[FilePermission]">
<dt><pre><span class="Keyword">proc</span> <a href="#setFilePermissions%2Cstring%2Cset%5BFilePermission%5D"><span class="Identifier">setFilePermissions</span></a><span class="Other">(</span><span class="Identifier">filename</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">permissions</span><span class="Other">:</span> <a href="system.html#set"><span class="Identifier">set</span></a><span class="Other">[</span><a href="osfiles.html#FilePermission"><span class="Identifier">FilePermission</span></a><span class="Other">]</span><span class="Other">;</span>
<span class="Identifier">followSymlinks</span> <span class="Other">=</span> <span class="Identifier">true</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;nos$1&quot;</span><span class="Other">,</span>
<span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="oscommon.html#ReadDirEffect"><span class="Identifier">ReadDirEffect</span></a><span class="Other">,</span> <a href="oscommon.html#WriteDirEffect"><span class="Identifier">WriteDirEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
<p>Sets the file permissions for <tt class="docutils literal"><span class="pre"><span class="Identifier">filename</span></span></tt>.</p>
<p>If <tt class="docutils literal"><span class="pre"><span class="Identifier">followSymlinks</span></span></tt> set to true (default) and <tt class="docutils literal"><span class="pre">filename</span></tt> points to a symlink, permissions are set to the file symlink points to. <tt class="docutils literal"><span class="pre"><span class="Identifier">followSymlinks</span></span></tt> set to false is a noop on Windows and some POSIX systems (including Linux) on which <tt class="docutils literal"><span class="pre"><span class="Identifier">lchmod</span></span></tt> is either unavailable or always fails, given that symlinks permissions there are not observed.</p>
<p><tt class="docutils literal"><span class="pre"><span class="Identifier">OSError</span></span></tt> is raised in case of an error. On Windows, only the <tt class="docutils literal"><span class="pre">readonly</span></tt> flag is changed, depending on <tt class="docutils literal"><span class="pre">fpUserWrite</span></tt> permission.</p>
<p>See also:</p>
<ul class="simple"><li><a class="reference internal nimdoc" title="proc getFilePermissions(filename: string): set[FilePermission]" href="#getFilePermissions,string">getFilePermissions proc</a></li>
<li><a class="reference internal nimdoc" title="enum FilePermission" href="#FilePermission">FilePermission enum</a></li>
</ul>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/private/osfiles.nim#L93" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/private/osfiles.nim#L93" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</div>
<div id="tryRemoveFile-procs-all">
<div id="tryRemoveFile,string">
<dt><pre><span class="Keyword">proc</span> <a href="#tryRemoveFile%2Cstring"><span class="Identifier">tryRemoveFile</span></a><span class="Other">(</span><span class="Identifier">file</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;nos$1&quot;</span><span class="Other">,</span>
<span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><a href="oscommon.html#WriteDirEffect"><span class="Identifier">WriteDirEffect</span></a><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
<p>Removes the <tt class="docutils literal"><span class="pre"><span class="Identifier">file</span></span></tt>.</p>
<p>If this fails, returns <tt class="docutils literal"><span class="pre"><span class="Identifier">false</span></span></tt>. This does not fail if the file never existed in the first place.</p>
<p>On Windows, ignores the read-only attribute.</p>
<p>See also:</p>
<ul class="simple"><li><a class="reference internal nimdoc" title="proc copyFile(source, dest: string; options = {cfSymlinkFollow}; bufferSize = 16384)" href="#copyFile,string,string,int">copyFile proc</a></li>
<li><a class="reference internal nimdoc" title="proc copyFileWithPermissions(source, dest: string; ignorePermissionErrors = true;
options = {cfSymlinkFollow})" href="#copyFileWithPermissions,string,string">copyFileWithPermissions proc</a></li>
<li><a class="reference internal nimdoc" title="proc removeFile(file: string)" href="#removeFile,string">removeFile proc</a></li>
<li><a class="reference internal nimdoc" title="proc moveFile(source, dest: string)" href="#moveFile,string,string">moveFile proc</a></li>
</ul>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/std/private/osfiles.nim#L339" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/std/private/osfiles.nim#L339" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</div>
</dl>
</div>
<div class="section" id="19">
<h1><a class="toc-backref" href="#19">Exports</a></h1>
<dl class="item">
<a href="oscommon.html#fileExists,string"><span class="Identifier">fileExists</span></a>
</dl>
</div>
</div>
</div>
<div class="twelve-columns footer">
<span class="nim-sprite"></span>
<br>
<small style="color: var(--hint);">Made with Nim. Generated: 2025-12-28 15:55:25 UTC</small>
</div>
</div>
</div>
<script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
</body>
</html>