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

📄 file.html

📁 perl教程
💻 HTML
📖 第 1 页 / 共 5 页
字号:
</dd>
</li>
</dl>
<p>Examples:</p>
<pre>
    <span class="variable">$hFlop</span><span class="operator">=</span> <span class="variable">createFile</span><span class="operator">(</span> <span class="string">"//./A:"</span><span class="operator">,</span> <span class="string">"r"</span><span class="operator">,</span> <span class="string">"r"</span> <span class="operator">)</span>
      <span class="keyword">or</span>  <span class="keyword">die</span> <span class="string">"Can't prevent others from writing to floppy: $^E\n"</span><span class="operator">;</span>
    <span class="variable">$hDisk</span><span class="operator">=</span> <span class="variable">createFile</span><span class="operator">(</span> <span class="string">"//./C:"</span><span class="operator">,</span> <span class="string">"rw ke"</span><span class="operator">,</span> <span class="string">""</span> <span class="operator">)</span>
      <span class="keyword">or</span>  <span class="keyword">die</span> <span class="string">"Can't get exclusive access to C: $^E\n"</span><span class="operator">;</span>
    <span class="variable">$hDisk</span><span class="operator">=</span> <span class="variable">createFile</span><span class="operator">(</span> <span class="variable">$sFilePath</span><span class="operator">,</span> <span class="string">"ke"</span><span class="operator">,</span>
      <span class="operator">{</span> <span class="string">Access</span><span class="operator">=&gt;</span><span class="variable">FILE_READ_ATTRIBUTES</span> <span class="operator">}</span> <span class="operator">)</span>
      <span class="keyword">or</span>  <span class="keyword">die</span> <span class="string">"Can't read attributes of $sFilePath: $^E\n"</span><span class="operator">;</span>
    <span class="variable">$hTemp</span><span class="operator">=</span> <span class="variable">createFile</span><span class="operator">(</span> <span class="string">"$ENV{Temp}/temp.$$"</span><span class="operator">,</span> <span class="string">"wn"</span><span class="operator">,</span> <span class="string">""</span><span class="operator">,</span>
      <span class="operator">{</span> <span class="string">Attributes</span><span class="operator">=&gt;</span><span class="string">"hst"</span><span class="operator">,</span> <span class="string">Flags</span><span class="operator">=&gt;</span><span class="variable">FILE_FLAG_DELETE_ON_CLOSE</span><span class="operator">()</span> <span class="operator">}</span> <span class="operator">)</span>
      <span class="keyword">or</span>  <span class="keyword">die</span> <span class="string">"Can't create temporary file, temp.$$: $^E\n"</span><span class="operator">;</span>
</pre>
<dt><strong><a name="item_getlogicaldrives">getLogicalDrives</a></strong>

<dt><strong><code>@roots= getLogicalDrives()</code></strong>

<dd>
<p>Returns the paths to the root directories of all logical drives
currently defined.  This includes all types of drive lettters, such
as floppies, CD-ROMs, hard disks, and network shares.  A typical
return value on a poorly equipped computer would be <code>(&quot;A:\\&quot;,&quot;C:\\&quot;)</code>.</p>
</dd>
</li>
<dt><strong><a name="item_closehandle">CloseHandle</a></strong>

<dt><strong><code>CloseHandle( $hObject )</code></strong>

<dd>
<p>Closes a Win32 native handle, such as one opened via <a href="#item_createfile"><code>CreateFile</code></a>. 
Like most routines, returns a true value if successful and a false
value [and sets <a href="../../lib/Pod/perlvar.html#item___e"><code>$^E</code></a> and <code>regLastError()</code>] on failure.</p>
</dd>
</li>
<dt><strong><a name="item_copyfile">CopyFile</a></strong>

<dt><strong><code>CopyFile( $sOldFileName, $sNewFileName, $bFailIfExists )</code></strong>

<dd>
<p><code>$sOldFileName</code> is the path to the file to be copied. 
<code>$sNewFileName</code> is the path to where the file should be copied. 
Note that you can <strong>NOT</strong> just specify a path to a directory in
<code>$sNewFileName</code> to copy the file to that directory using the
same file name.</p>
</dd>
<dd>
<p>If <code>$bFailIfExists</code> is true and <code>$sNewFileName</code> is the path to
a file that already exists, then <a href="#item_copyfile"><code>CopyFile</code></a> will fail.  If
<code>$bFailIfExists</code> is falsea, then the copy of the <code>$sOldFileNmae</code>
file will overwrite the <code>$sNewFileName</code> file if it already exists.</p>
</dd>
<dd>
<p>Like most routines, returns a true value if successful and a false
value [and sets <a href="../../lib/Pod/perlvar.html#item___e"><code>$^E</code></a> and <code>regLastError()</code>] on failure.</p>
</dd>
</li>
<dt><strong><a name="item_createfile">CreateFile</a></strong>

<dt><strong><code>$hObject= CreateFile( $sPath, $uAccess, $uShare, $pSecAttr, $uCreate, $uFlags, $hModel )</code></strong>

<dd>
<p>On failure, <code>$hObject</code> gets set to a false value and <a href="../../lib/Pod/perlvar.html#item___e"><code>$^E</code></a> and
<a href="#item_filelasterror"><code>fileLastError()</code></a> are set to the reason for the failure.  Otherwise,
<code>$hObject</code> gets set to a Win32 native file handle which is always 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.</p>
</dd>
<dd>
<p><code>$sPath</code> can use <code>&quot;/&quot;</code> or <code>&quot;\\&quot;</code> as path delimiters and can even
mix the two.  We will usually only use <code>&quot;/&quot;</code> in our examples since
using <code>&quot;\\&quot;</code> is usually harder to read.</p>
</dd>
<dd>
<p>Under Windows NT, <code>$sPath</code> can start with <code>&quot;//?/&quot;</code> to allow the use
of paths longer than <code>MAX_PATH</code> [for UNC paths, replace the leading
<code>&quot;//&quot;</code> with <code>&quot;//?/UNC/&quot;</code>, as in <code>&quot;//?/UNC/Server/Share/Dir/File.Ext&quot;</code>].</p>
</dd>
<dd>
<p><code>$sPath</code> can start with <code>&quot;//./&quot;</code> to indicate that the rest of the
path is the name of a &quot;DOS device.&quot;  You can use <a href="#item_querydosdevice"><code>QueryDosDevice</code></a>
to list all current DOS devices and can add or delete them with
<a href="#item_definedosdevice"><code>DefineDosDevice</code></a>.  If you get the source-code distribution of this
module from CPAN, then it includes an example script, <em>ex/ListDevs.plx</em>
that will list all current DOS devices and their &quot;native&quot; definition.
Again, note that this doesn't work under Win95 nor Win98.</p>
</dd>
<dd>
<p>The most common such DOS devices include:</p>
</dd>
<dl>
<dt><strong><a name="item__22_2f_2f_2e_2fphysicaldrive0_22"><code>&quot;//./PhysicalDrive0&quot;</code></a></strong>

<dd>
<p>Your entire first hard disk.  Doesn't work under Windows 95.  This
allows you to read or write raw sectors of your hard disk and to use
<a href="#item_deviceiocontrol"><code>DeviceIoControl</code></a> to perform miscellaneous queries and operations
to the hard disk.   Writing raw sectors and certain other operations
can seriously damage your files or the function of your computer.</p>
</dd>
<dd>
<p>Locking this for exclusive access [by specifying <code>0</code> for <code>$uShare</code>]
doesn't prevent access to the partitions on the disk nor their file
systems.  So other processes can still access any raw sectors within
a partition and can use the file system on the disk as usual.</p>
</dd>
</li>
<dt><strong><a name="item__22_2f_2f_2e_2fc_3a_22"><code>&quot;//./C:&quot;</code></a></strong>

<dd>
<p>Your <em>C:</em> partition.  Doesn't work under Windows 95.  This allows
you to read or write raw sectors of that partition and to use
<a href="#item_deviceiocontrol"><code>DeviceIoControl</code></a> to perform miscellaneous queries and operations
to the partition.  Writing raw sectors and certain other operations
can seriously damage your files or the function of your computer.</p>
</dd>
<dd>
<p>Locking this for exclusive access doesn't prevent access to the
physical drive that the partition is on so other processes can
still access the raw sectors that way.  Locking this for exclusive
access <strong>does</strong> prevent other processes from opening the same raw
partition and <strong>does</strong> prevent access to the file system on it.  It
even prevents the current process from accessing the file system
on that partition.</p>
</dd>
</li>
<dt><strong><a name="item__22_2f_2f_2e_2fa_3a_22"><code>&quot;//./A:&quot;</code></a></strong>

<dd>
<p>The raw floppy disk.  Doesn't work under Windows 95.  This allows
you to read or write raw sectors of the floppy disk and to use
<a href="#item_deviceiocontrol"><code>DeviceIoControl</code></a> to perform miscellaneous queries and operations
to the floopy disk or drive.</p>
</dd>
<dd>
<p>Locking this for exclusive access prevents all access to the floppy.</p>
</dd>
</li>
<dt><strong><a name="item__22_2f_2f_2e_2fpipe_2fpipename_22"><code>&quot;//./PIPE/PipeName&quot;</code></a></strong>

<dd>
<p>A named pipe, created via <code>CreateNamedPipe</code>.</p>
</dd>
</li>
</dl>
<p><code>$uAccess</code> is an unsigned value with bits set indicating the
type of access desired.  Usually either <code>0</code> [&quot;query&quot; access],
<code>GENERIC_READ</code>, <code>GENERIC_WRITE</code>, <code>GENERIC_READ|GENERIC_WRITE</code>,
or <code>GENERIC_ALL</code>.  More specific types of access can be specified,
such as <code>FILE_APPEND_DATA</code> or <code>FILE_READ_EA</code>.</p>
<p><code>$uShare</code> controls how the file is shared, that is, whether other
processes can have read, write, and/or delete access to the file while
we have it opened.  <code>$uShare</code> is an unsigned value with zero or more
of these bits set:  <code>FILE_SHARE_READ</code>, <code>FILE_SHARE_WRITE</code>, and
<code>FILE_SHARE_DELETE</code>.</p>
<p>If another process currently has read, write, and/or delete access to
the file and you don't allow that level of sharing, then your call to
<a href="#item_createfile"><code>CreateFile</code></a> will fail.  If you requested read, write, and/or delete
access and another process already has the file open but doesn't allow
that level of sharing, thenn your call to <a href="#item_createfile"><code>createFile</code></a> will fail.  Once
you have the file open, if another process tries to open it with read,
write, and/or delete access and you don't allow that level of sharing,
then that process won't be allowed to open the file.</p>
<p><code>$pSecAttr</code> should either be <code>[]</code> [for <code>NULL</code>] or a
<code>SECURITY_ATTRIBUTES</code> data structure packed into a string.
For example, if <code>$pSecDesc</code> contains a <code>SECURITY_DESCRIPTOR</code>
structure packed into a string, perhaps via:</p>
<pre>
    <span class="variable">RegGetKeySecurity</span><span class="operator">(</span> <span class="variable">$key</span><span class="operator">,</span> <span class="number">4</span><span class="operator">,</span> <span class="variable">$pSecDesc</span><span class="operator">,</span> <span class="number">1024</span> <span class="operator">);</span>
</pre>
<p>then you can set <code>$pSecAttr</code> via:</p>
<pre>
    <span class="variable">$pSecAttr</span><span class="operator">=</span> <span class="keyword">pack</span><span class="operator">(</span> <span class="string">"L P i"</span><span class="operator">,</span> <span class="number">12</span><span class="operator">,</span> <span class="variable">$pSecDesc</span><span class="operator">,</span> <span class="variable">$bInheritHandle</span> <span class="operator">);</span>
</pre>
<p><code>$uCreate</code> is one of the following values:  <code>OPEN_ALWAYS</code>,
<code>OPEN_EXISTING</code>, <code>TRUNCATE_EXISTING</code>, <code>CREATE_ALWAYS</code>, and
<code>CREATE_NEW</code>.</p>
<p><code>$uFlags</code> is an unsigned value with zero or more bits set indicating
attributes to associate with the file [<code>FILE_ATTRIBUTE_*</code> values] or
special options [<code>FILE_FLAG_*</code> values].</p>
<p>If opening the client side of a named pipe, then you can also set
<code>$uFlags</code> to include <code>SECURITY_SQOS_PRESENT</code> along with one of the
other <code>SECURITY_*</code> constants to specify the security quality of
service to be used.</p>
<p><code>$hModel</code> is <code>0</code> [or <code>[]</code>, both of which mean <code>NULL</code>] or a Win32
native handle opened with <code>GENERIC_READ</code> access to a model file from
which file attributes and extended attributes are to be copied if a
new file gets created.</p>
<p>Examples:</p>
<pre>
    <span class="variable">$hFlop</span><span class="operator">=</span> <span class="variable">CreateFile</span><span class="operator">(</span> <span class="string">"//./A:"</span><span class="operator">,</span> <span class="variable">GENERIC_READ</span><span class="operator">(),</span>
      <span class="variable">FILE_SHARE_READ</span><span class="operator">(),</span> <span class="operator">[]</span><span class="operator">,</span> <span class="variable">OPEN_EXISTING</span><span class="operator">(),</span> <span class="number">0</span><span class="operator">,</span> <span class="operator">[]</span> <span class="operator">)</span>
      <span class="keyword">or</span>  <span class="keyword">die</span> <span class="string">"Can't prevent others from writing to floppy: $^E\n"</span><span class="operator">;</span>
    <span class="variable">$hDisk</span><span class="operator">=</span> <span class="variable">createFile</span><span class="operator">(</span> <span class="variable">$sFilePath</span><span class="operator">,</span> <span class="variable">FILE_READ_ATTRIBUTES</span><span class="operator">(),</span>
      <span class="variable">FILE_SHARE_READ</span><span class="operator">()|</span><span class="variable">FILE_SHARE_WRITE</span><span class="operator">(),</span> <span class="operator">[]</span><span class="operator">,</span> <span class="variable">OPEN_EXISTING</span><span class="operator">(),</span> <span class="number">0</span><span class="operator">,</span> <span class="operator">[]</span> <span class="operator">)</span>
      <span class="keyword">or</span>  <span class="keyword">die</span> <span class="string">"Can't read attributes of $sFilePath: $^E\n"</span><span class="operator">;</span>
    <span class="variable">$hTemp</span><span class="operator">=</span> <span class="variable">createFile</span><span class="operator">(</span> <span class="string">"$ENV{Temp}/temp.$$"</span><span class="operator">,</span> <span class="variable">GENERIC_WRITE</span><span class="operator">(),</span> <span class="number">0</span><span class="operator">,</span>
      <span class="variable">CREATE_NEW</span><span class="operator">(),</span> <span class="variable">FILE_FLAG_DELETE_ON_CLOSE</span><span class="operator">()|</span><span class="variable">attrLetsToBits</span><span class="operator">(</span><span class="string">"hst"</span><span class="operator">),</span> <span class="operator">[]</span> <span class="operator">)</span>
      <span class="keyword">or</span>  <span class="keyword">die</span> <span class="string">"Can't create temporary file, temp.$$: $^E\n"</span><span class="operator">;</span>
</pre>
<dt><strong><a name="item_definedosdevice">DefineDosDevice</a></strong>

<dt><strong><code>DefineDosDevice( $uFlags, $sDosDeviceName, $sTargetPath )</code></strong>

<dd>
<p>Defines a new DOS device, overrides the current definition of a DOS
device, or deletes a definition of a DOS device.  Like most routines,
returns a true value if successful and a false value [and sets <a href="../../lib/Pod/perlvar.html#item___e"><code>$^E</code></a>
and <code>regLastError()</code>] on failure.</p>
</dd>
<dd>
<p><code>$sDosDeviceName</code> is the name of a DOS device for which we'd like
to add or delete a definition.</p>
</dd>
<dd>
<p><code>$uFlags</code> is an unsigned value with zero or more of the following
bits set:</p>
</dd>
<dl>
<dt><strong><a name="item_ddd_raw_target_path"><code>DDD_RAW_TARGET_PATH</code></a></strong>

<dd>
<p>Indicates that <code>$sTargetPath</code> will be a raw Windows NT object name. 
This usually means that <code>$sTargetPath</code> starts with <code>&quot;\\Device\\&quot;</code>. 
Note that you cannot use <code>&quot;/&quot;</code> in place of <code>&quot;\\&quot;</code> in raw target path
names.</p>
</dd>
</li>
<dt><strong><a name="item_ddd_remove_definition"><code>DDD_REMOVE_DEFINITION</code></a></strong>

<dd>

⌨️ 快捷键说明

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