本文采用C#语言实现创建,删除和移动文件夹以及文件夹列表的功能,代码如下:
使用Directory类和DirectoryInfo类
一:创建文件夹
二:删除文件夹
try
三:移动文件夹
源文件夹和目标文件夹要求存在于同一个硬盘分区中否则会操作失败(操作失败! 失败原因:System.IO.IOException: 源路径和目标路径必须具有相同的根。移动操作在卷之间无效。 在
四:文件夹列表
<table border="1">
<tr>
<td colspan="2" style="color: #660066;">
文件夹中文件列表:
</td>
</tr>
<tr>
<td style="font-size: 10pt">
请输入要删除文件的路径:
</td>
<td style="width: 158px">
<asp:TextBox ID="DirectoryTextBox" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="MsgLabel" runat="server" ForeColor="red"></asp:Label>
</td>
</tr>
<tr>
<td colspan="2" style="width: 158px">
<asp:ListBox ID="FileListBox" runat="server" Height="192px" Width="184px"></asp:ListBox>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:Button ID="ExistButton" runat="server" Text="确定" OnClick="ExistButton_Click" />
</td>
</tr>
</table>