相關代碼如下:
DirectoryInfo dirInfo = new DirectoryInfo(dirPath);
if (dirInfo.GetFiles().Length != 0)
{
//If Block
}
在執行GetFiles方法時拋出DircetoryNotFoundException,但是我檢查了無數次,確認dirPath這個路徑是存在的。
DirectoryInfo dirInfo = new DirectoryInfo(dirPath);
if (dirInfo.GetFiles().Length != 0)
{
//If Block
}
在執行GetFiles方法時拋出DircetoryNotFoundException,但是我檢查了無數次,確認dirPath這個路徑是存在的。
http://www.cnblogs.com/qiao198/archive/2005/11/12/274732.html文章中的用户可能不对
实际用户是:
NETWORK SERVICE -- WIN2003
ASPNET -- winxp
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;namespace ClearBrowserCache
{
class Program
{
static void Main(string[] args)
{
StreamWriter stw = new StreamWriter(args[1], false);
bool flag = false;
string browserCacheFolder;
switch (args[0].ToUpper())
{
case "IE":
browserCacheFolder = @"\Windows\Profiles\guest\Temporary Internet Files\Content.IE5\";
flag = ClearDirectory(browserCacheFolder);
break;
case "OPERA":
browserCacheFolder = @"\Application Data\Oprea9\cache\";
flag = ClearDirectory(browserCacheFolder);
break;
default:
break;
}
stw.Write(flag.ToString());
stw.Close();
}
static bool ClearDirectory(string dirPath)
{
//try
//{
DirectoryInfo dirInfo = new DirectoryInfo(dirPath);
if (dirInfo.GetFiles().Length != 0)
{
foreach (FileInfo f in dirInfo.GetFiles())
f.Delete();
}
if (dirInfo.GetDirectories().Length != 0)
{
foreach (DirectoryInfo d in dirInfo.GetDirectories())
d.Delete(true);
}
if (Directory.GetDirectories(dirPath).Length == 0 && Directory.GetFiles(dirPath).Length == 0)
return true;
else
return false;
//}
//catch
//{
// return false;
//}
}
}
}
using System.IO;public class DirectoryInfoTest
{
public static void Main()
{
string m_path = @"c:\files"; //设置所要检测文件夹的绝对路径
DirectoryInfo m_DirInfo = new DirectoryInfo(m_path); //以路径为参数构造DirectoryInfo对象
if (m_DirInfo.Exists) //检测文件夹是否存在
{
Console.WriteLine("Directory Exists!");
}
else
{
Console.WriteLine("Directory Not Exists!");
}
Console.ReadLine();
}
}