⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 file.html

📁 perl教程
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<?xml version="1.0" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- saved from url=(0017)http://localhost/ -->
<script language="JavaScript" src="../../displayToc.js"></script>
<script language="JavaScript" src="../../tocParas.js"></script>
<script language="JavaScript" src="../../tocTab.js"></script>
<link rel="stylesheet" type="text/css" href="../../scineplex.css">
<title>Win32API::File - Low-level access to Win32 system API calls for files/dirs.</title>
<link rel="stylesheet" href="../../Active.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>

<body>

<script>writelinks('__top__',2);</script>
<h1><a>Win32API::File - Low-level access to Win32 system API calls for files/dirs.</a></h1>
<p><a name="__index__"></a></p>

<!-- INDEX BEGIN -->

<ul>

	<li><a href="#name">NAME</a></li>
	<li><a href="#synopsis">SYNOPSIS</a></li>
	<li><a href="#description">DESCRIPTION</a></li>
	<ul>

		<li><a href="#object_oriented_tied_handle_interface">Object Oriented/Tied Handle Interface</a></li>
		<li><a href="#exports">Exports</a></li>
	</ul>

	<li><a href="#bugs">BUGS</a></li>
	<li><a href="#author">AUTHOR</a></li>
	<li><a href="#see_also">SEE ALSO</a></li>
</ul>
<!-- INDEX END -->

<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>Win32API::File - Low-level access to Win32 system API calls for files/dirs.</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
  <span class="keyword">use</span> <span class="variable">Win32API::File</span> <span class="number">0</span><span class="operator">.</span><span class="number">08</span> <span class="string">qw( :ALL )</span><span class="operator">;</span>
</pre>
<pre>
  <span class="variable">MoveFile</span><span class="operator">(</span> <span class="variable">$Source</span><span class="operator">,</span> <span class="variable">$Destination</span> <span class="operator">)</span>
    <span class="keyword">or</span>  <span class="keyword">die</span> <span class="string">"Can't move $Source to $Destination: "</span><span class="operator">,</span><span class="variable">fileLastError</span><span class="operator">(),</span><span class="string">"\n"</span><span class="operator">;</span>
  <span class="variable">MoveFileEx</span><span class="operator">(</span> <span class="variable">$Source</span><span class="operator">,</span> <span class="variable">$Destination</span><span class="operator">,</span> <span class="variable">MOVEFILE_REPLACE_EXISTING</span><span class="operator">()</span> <span class="operator">)</span>
    <span class="keyword">or</span>  <span class="keyword">die</span> <span class="string">"Can't move $Source to $Destination: "</span><span class="operator">,</span><span class="variable">fileLastError</span><span class="operator">(),</span><span class="string">"\n"</span><span class="operator">;</span>
  <span class="operator">[</span><span class="operator">...</span><span class="operator">]</span>
</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>This provides fairly low-level access to the Win32 System API
calls dealing with files and directories.</p>
<p>To pass in <code>NULL</code> as the pointer to an optional buffer, pass in
an empty list reference, <code>[]</code>.</p>
<p>Beyond raw access to the API calls and related constants, this module
handles smart buffer allocation and translation of return codes.</p>
<p>All functions, unless otherwise noted, return a true value for success
and a false value for failure and set <a href="../../lib/Pod/perlvar.html#item___e"><code>$^E</code></a> on failure.</p>
<p>
</p>
<h2><a name="object_oriented_tied_handle_interface">Object Oriented/Tied Handle Interface</a></h2>
<p>WARNING: this is new code, use at your own risk.</p>
<p>This version of <code>Win32API::File</code> can be used like an <code>IO::File</code> object:</p>
<pre>
  <span class="keyword">my</span> <span class="variable">$file</span> <span class="operator">=</span> <span class="variable">new</span> <span class="variable">Win32API::File</span> <span class="string">"+&gt; foo"</span><span class="operator">;</span>
  <span class="keyword">binmode</span> <span class="variable">$file</span><span class="operator">;</span>
  <span class="keyword">print</span> <span class="variable">$file</span> <span class="string">"hello there\n"</span><span class="operator">;</span>
  <span class="keyword">seek</span> <span class="variable">$file</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">;</span>
  <span class="keyword">my</span> <span class="variable">$line</span> <span class="operator">=</span> <span class="operator">&lt;</span><span class="variable">$file</span><span class="operator">&gt;;</span>
  <span class="variable">$file</span><span class="operator">-&gt;</span><span class="keyword">close</span><span class="operator">;</span>
</pre>
<p>It also supports tying via a win32 handle (for example, from <a href="#item_createfile"><code>createFile()</code></a>):</p>
<pre>
  <span class="keyword">tie</span> <span class="variable">FILE</span><span class="operator">,</span> <span class="string">'Win32API::File'</span><span class="operator">,</span> <span class="variable">$win32_handle</span><span class="operator">;</span>
  <span class="keyword">print</span> <span class="variable">FILE</span> <span class="string">"..."</span><span class="operator">;</span>
</pre>
<p>It has not been extensively tested yet and buffered I/O is not yet implemented.</p>
<p>
</p>
<h2><a name="exports">Exports</a></h2>
<p>Nothing is exported by default.  The following tags can be used to
have large sets of symbols exported:  <a href="#item__22_3afunc_22"><code>&quot;:Func&quot;</code></a>, <a href="#item__22_3afunca_22"><code>&quot;:FuncA&quot;</code></a>,
<a href="#item__22_3afuncw_22"><code>&quot;:FuncW&quot;</code></a>, <a href="#item__22_3amisc_22"><code>&quot;:Misc&quot;</code></a>, <a href="#item__22_3addd__22"><code>&quot;:DDD_&quot;</code></a>, <a href="#item__22_3adrive__22"><code>&quot;:DRIVE_&quot;</code></a>, <a href="#item__22_3afile__22"><code>&quot;:FILE_&quot;</code></a>,
<a href="#item__22_3afile_attribute__22"><code>&quot;:FILE_ATTRIBUTE_&quot;</code></a>, <a href="#item__22_3afile_flag__22"><code>&quot;:FILE_FLAG_&quot;</code></a>, <a href="#item__22_3afile_share__22"><code>&quot;:FILE_SHARE_&quot;</code></a>,
<a href="#item__22_3afile_type__22"><code>&quot;:FILE_TYPE_&quot;</code></a>, <a href="#item__22_3afs__22"><code>&quot;:FS_&quot;</code></a>, <a href="#item__22_3afsctl__22"><code>&quot;:FSCTL_&quot;</code></a>, <a href="#item__22_3ahandle_flag__22"><code>&quot;:HANDLE_FLAG_&quot;</code></a>,
<a href="#item__22_3aioctl_storage__22"><code>&quot;:IOCTL_STORAGE_&quot;</code></a>, <a href="#item__22_3aioctl_disk__22"><code>&quot;:IOCTL_DISK_&quot;</code></a>, <a href="#item__22_3ageneric__22"><code>&quot;:GENERIC_&quot;</code></a>,
<a href="#item__22_3amedia_type_22"><code>&quot;:MEDIA_TYPE&quot;</code></a>, <a href="#item__22_3amovefile__22"><code>&quot;:MOVEFILE_&quot;</code></a>, <a href="#item__22_3asecurity__22"><code>&quot;:SECURITY_&quot;</code></a>, <a href="#item__22_3asem__22"><code>&quot;:SEM_&quot;</code></a>,
and <a href="#item__22_3apartition__22"><code>&quot;:PARTITION_&quot;</code></a>.</p>
<dl>
<dt><strong><a name="item__22_3afunc_22"><code>&quot;:Func&quot;</code></a></strong>

<dd>
<p>The basic function names:  <a href="#item_attrletstobits"><code>attrLetsToBits</code></a>,         <a href="#item_createfile"><code>createFile</code></a>,
<a href="#item_fileconstant"><code>fileConstant</code></a>,           <a href="#item_filelasterror"><code>fileLastError</code></a>,          <a href="#item_getlogicaldrives"><code>getLogicalDrives</code></a>,
<a href="#item_setfilepointer"><code>setFilePointer</code></a>,         <a href="#item_getfilesize"><code>getFileSize</code></a>,
<a href="#item_closehandle"><code>CloseHandle</code></a>,            <a href="#item_copyfile"><code>CopyFile</code></a>,               <a href="#item_createfile"><code>CreateFile</code></a>,
<a href="#item_definedosdevice"><code>DefineDosDevice</code></a>,        <a href="#item_deletefile"><code>DeleteFile</code></a>,             <a href="#item_deviceiocontrol"><code>DeviceIoControl</code></a>,
<a href="#item_fdgetosfhandle"><code>FdGetOsFHandle</code></a>,         <a href="#item_getdrivetype"><code>GetDriveType</code></a>,           <a href="#item_getfileattributes"><code>GetFileAttributes</code></a>,
<a href="#item_getfilesize"><code>GetFileSize</code></a>,            <a href="#item_getfiletype"><code>GetFileType</code></a>,            <a href="#item_gethandleinformation"><code>GetHandleInformation</code></a>,
<a href="#item_getlogicaldrives"><code>GetLogicalDrives</code></a>,       <a href="#item_getlogicaldrivestrings"><code>GetLogicalDriveStrings</code></a>, <a href="#item_getosfhandle"><code>GetOsFHandle</code></a>,
<a href="#item_getoverlappedresult"><code>GetOverlappedResult</code></a>,    <a href="#item_getvolumeinformation"><code>GetVolumeInformation</code></a>,   <a href="#item_iscontainerpartition"><code>IsContainerPartition</code></a>,
<a href="#item_isrecognizedpartition"><code>IsRecognizedPartition</code></a>,  <a href="#item_movefile"><code>MoveFile</code></a>,               <a href="#item_movefileex"><code>MoveFileEx</code></a>,
<a href="#item_osfhandleopen"><code>OsFHandleOpen</code></a>,          <a href="#item_osfhandleopenfd"><code>OsFHandleOpenFd</code></a>,        <a href="#item_querydosdevice"><code>QueryDosDevice</code></a>,
<a href="#item_readfile"><code>ReadFile</code></a>,               <a href="#item_seterrormode"><code>SetErrorMode</code></a>,           <a href="#item_setfilepointer"><code>SetFilePointer</code></a>,
<a href="#item_sethandleinformation"><code>SetHandleInformation</code></a>,   and <a href="#item_writefile"><code>WriteFile</code></a>.</p>
</dd>
<dl>
<dt><strong><a name="item_attrletstobits">attrLetsToBits</a></strong>

<dt><strong><code>$uBits= attrLetsToBits( $sAttributeLetters )</code></strong>

<dd>
<p>Converts a string of file attribute letters into an unsigned value with
the corresponding bits set.  <code>$sAttributeLetters</code> should contain zero
or more letters from <code>&quot;achorst&quot;</code>:</p>
</dd>
<dl>
<dt><strong><a name="item__22a_22"><code>&quot;a&quot;</code></a></strong>

<dd>
<p><a href="#item_file_attribute_archive"><code>FILE_ATTRIBUTE_ARCHIVE</code></a></p>
</dd>
</li>
<dt><strong><a name="item__22c_22"><code>&quot;c&quot;</code></a></strong>

<dd>
<p><a href="#item_file_attribute_compressed"><code>FILE_ATTRIBUTE_COMPRESSED</code></a></p>
</dd>
</li>
<dt><strong><a name="item__22h_22"><code>&quot;h&quot;</code></a></strong>

<dd>
<p><a href="#item_file_attribute_hidden"><code>FILE_ATTRIBUTE_HIDDEN</code></a></p>
</dd>
</li>
<dt><strong><a name="item__22o_22"><code>&quot;o&quot;</code></a></strong>

<dd>
<p><a href="#item_file_attribute_offline"><code>FILE_ATTRIBUTE_OFFLINE</code></a></p>
</dd>
</li>
<dt><strong><a name="item__22r_22"><code>&quot;r&quot;</code></a></strong>

<dd>
<p><a href="#item_file_attribute_readonly"><code>FILE_ATTRIBUTE_READONLY</code></a></p>
</dd>
</li>
<dt><strong><a name="item__22s_22"><code>&quot;s&quot;</code></a></strong>

<dd>
<p><a href="#item_file_attribute_system"><code>FILE_ATTRIBUTE_SYSTEM</code></a></p>
</dd>
</li>
<dt><strong><a name="item__22t_22"><code>&quot;t&quot;</code></a></strong>

<dd>
<p><a href="#item_file_attribute_temporary"><code>FILE_ATTRIBUTE_TEMPORARY</code></a></p>
</dd>
</li>
</dl>
<dt><strong><a name="item_createfile">createFile</a></strong>

<dt><strong><code>$hObject= createFile( $sPath )</code></strong>

<dt><strong><code>$hObject= createFile( $sPath, $rvhvOptions )</code></strong>

<dt><strong><code>$hObject= createFile( $sPath, $svAccess )</code></strong>

<dt><strong><code>$hObject= createFile( $sPath, $svAccess, $rvhvOptions )</code></strong>

<dt><strong><code>$hObject= createFile( $sPath, $svAccess, $svShare )</code></strong>

<dt><strong><code>$hObject= createFile( $sPath, $svAccess, $svShare, $rvhvOptions )</code></strong>

<dd>
<p>This is a Perl-friendly wrapper around <a href="#item_createfile"><code>CreateFile</code></a>.</p>
</dd>
<dd>
<p>On failure, <code>$hObject</code> gets set to a false value and <code>regLastError()</code>
and <a href="../../lib/Pod/perlvar.html#item___e"><code>$^E</code></a> are set to the reason for the failure.  Otherwise,
<code>$hObject</code> gets set to a Win32 native file handle which is alwasy
a true value [returns <code>&quot;0 but true&quot;</code> in the <code>impossible(?)</code> case of
the handle having a value of <code>0</code>].</p>
</dd>
<dd>
<p><code>$sPath</code> is the path to the file [or device, etc.] to be opened.  See
<a href="#item_createfile"><code>CreateFile</code></a> for more information on possible special values for
<code>$sPath</code>.</p>
</dd>
<dd>
<p><code>$svAccess</code> can be a number containing the bit mask representing
the specific <code>type(s)</code> of access to the file that you desire.  See the
<code>$uAccess</code> parameter to <a href="#item_createfile"><code>CreateFile</code></a> for more information on these
values.</p>
</dd>
<dd>
<p>More likely, <code>$svAccess</code> is a string describing the generic type of
access you desire and possibly the file creation options to use.  In
this case, <code>$svAccess</code> should contain zero or more characters from
<code>&quot;qrw&quot;</code> [access desired], zero or one character each from <code>&quot;ktn&quot;</code>
and <code>&quot;ce&quot;</code>, and optional white space.  These letters stand for,
respectively, &quot;Query access&quot;, &quot;Read access&quot;, &quot;Write access&quot;, &quot;Keep if
exists&quot;, &quot;Truncate if exists&quot;, &quot;New file only&quot;, &quot;Create if none&quot;, and
&quot;Existing file only&quot;.  Case is ignored.</p>
</dd>
<dd>
<p>You can pass in <code>&quot;?&quot;</code> for <code>$svAccess</code> to have an error message
displayed summarizing its possible values.  This is very handy when
doing on-the-fly programming using the Perl debugger:</p>
</dd>
<dd>
<pre>
    Win32API::File::createFile:  $svAccess can use the following:
        One or more of the following:
            q -- Query access (same as 0)
            r -- Read access (GENERIC_READ)
            w -- Write access (GENERIC_WRITE)
        At most one of the following:
            k -- Keep if exists
            t -- Truncate if exists
            n -- New file only (fail if file already exists)
        At most one of the following:
            c -- Create if doesn't exist

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -