截止2004年12月16日 |
本站源码总量(商业源码除外)RAR压缩为 4,206,733 KB。其中免费源码为 1,124,495 KB,会员源码为 3,082,238 KB!
C/C++ |
129,555 KB |
Delphi |
1,258,381 KB |
Java |
120,937 KB |
.Net |
36,886 KB |
PowerBuilder |
954,525 KB |
Visual Basic |
923,454 KB |
ASP |
259,795 KB |
JSP |
4,987 KB |
其他 |
94,723 KB |
|
|
删除指定目录里的所有文件 |
|
VB.NET
<System.ComponentModel.Description "删除目录内所有文件")> _
Public Shared Function DelFiles )Function DelFiles ByVal sPhysicalDirectory As System.String, Optional ByVal isPhysicalDirectory As Boolean = True) As Boolean
Dim oDirectoryInfo As System.IO.DirectoryInfo
Dim oFileInfo As System.IO.FileInfo
If isPhysicalDirectory = False Then
sPhysicalDirectory = System.Web.HttpContext.Current.Server.MapPath sPhysicalDirectory)
End If
Try
If System.IO.Directory.Exists sPhysicalDirectory) = False Then Exit Function
oDirectoryInfo = New System.IO.DirectoryInfo sPhysicalDirectory)
For Each oFileInfo In oDirectoryInfo.GetFiles
System.IO.File.Delete oFileInfo.FullName)
Next
Return True
Catch ex As System.Exception
Common.Exception.Append ex)
Return False
End Try
End Function
|
C#
[
System.ComponentModel.Description "删除目录内所有文件")]
public static bool DelFiles System.String sPhysicalDirectory)
{
DelFiles sPhysicalDirectory, true)
}
[System.ComponentModel.Description "删除目录内所有文件")]
public static bool DelFiles System.String sPhysicalDirectory, bool isPhysicalDirectory)
{
System.IO.DirectoryInfo oDirectoryInfo;
System.IO.FileInfo oFileInfo;
if isPhysicalDirectory == false) {
sPhysicalDirectory = System.Web.HttpContext.Current.Server.MapPath sPhysicalDirectory);
}
try {
if System.IO.Directory.Exists sPhysicalDirectory) == false) {
goto exitMethodDeclaration0;
}
oDirectoryInfo = new System.IO.DirectoryInfo sPhysicalDirectory);
foreach int oFileInfo in oDirectoryInfo.GetFiles) {
System.IO.File.Delete oFileInfo.FullName);
}
return true;
} catch System.Exception ex) {
Common.Exception.Append ex);
return false;
}
exitMethodDeclaration0: ;
}
|
1 建议不调用CMD执行rd的命令
2 删除目录、目录内的子目录以及目录内所有文件
VB.NET语法
<System.ComponentModel.Description "删除目录、目录内的子目录以及目录内所有文件")> _
Public Shared Sub DelDirectory )Sub DelDirectory ByVal sDirectory As System.String, Optional ByVal isPhysicalDirectory As Boolean = True)
Dim sBaseFile As String
Dim sBaseDirectory As String
If isPhysicalDirectory = False Then
sBaseDirectory = System.Web.HttpContext.Current.Server.MapPath sDirectory)
Else
sBaseDirectory = sDirectory
End If
Try
If System.IO.Directory.Exists sBaseDirectory) = False Then Exit Sub
For Each sBaseFile In System.IO.Directory.GetFiles sBaseDirectory)
System.IO.File.Delete sBaseFile)
Next
For Each sBaseDirectory In System.IO.Directory.GetDirectories sBaseDirectory)
DelDirectory sBaseDirectory, True)
If System.IO.Directory.GetFiles sBaseDirectory).Length = 0 And System.IO.Directory.GetDirectories sBaseDirectory).Length = 0 Then
System.IO.Directory.Delete sBaseDirectory)
End If
Next
Catch ex As System.Exception
Common.Exception.Append ex)
End Try
End Sub
|
C#语法
[System.ComponentModel.Description "删除目录、目录内的子目录以及目录内所有文件")]
public static void DelDirectory System.String sDirectory)
{
DelDirectory sDirectory, true);
}
[System.ComponentModel.Description "删除目录、目录内的子目录以及目录内所有文件")]
public static void DelDirectory System.String sDirectory, bool isPhysicalDirectory)
{
//string sBaseFile;
string sBaseDirectory;
if isPhysicalDirectory == false)
{
sBaseDirectory = System.Web.HttpContext.Current.Server.MapPath sDirectory);
}
else
{
sBaseDirectory = sDirectory;
}
try
{
if System.IO.Directory.Exists sBaseDirectory) == false)
{
goto exitMethodDeclaration0;
}
foreach string sPhysicalFile in System.IO.Directory.GetFiles sBaseDirectory))
{
System.IO.File.Delete sPhysicalFile);
}
foreach string sPhysicalDirectory in System.IO.Directory.GetDirectories sBaseDirectory))
{
DelDirectory sPhysicalDirectory, true);
if System.IO.Directory.GetFiles sPhysicalDirectory).Length == 0 & System.IO.Directory.GetDirectories sPhysicalDirectory).Length == 0)
{
System.IO.Directory.Delete sPhysicalDirectory);
}
}
}
catch System.Exception ex)
{
//Common.Exception.Append ex);
System.Web.HttpContext.Current.Response.Write ex.Message);
}
exitMethodDeclaration0: ;
}
|
|
|
文章出处: |
|
发表时间:2004-11-22 23:09:04 |
共1条数据记录,分1页显示 上一页 < [1] > 下一页 |
|