C#文件及目录处理
public string DisposeDirc(string SendPath,bool DisposeType)
{
try
{
if(SendPath.Substring(SendPath.Length - 1,1) != @"\")
SendPath = SendPath + @"\";
DirectoryInfo dirc = new DirectoryInfo(SendPath);
string DircSum = "";
if(dirc.Exists)
{
if(DisposeType)
{
foreach(DirectoryInfo Dic in dirc.GetDirectories())
{
if(DircSum == "")
DircSum = Dic.Name;
else
DircSum = DircSum + '|' + Dic.Name;
}
}
else
{
dirc.Delete(true);
DircSum = " ";
}
}
return DircSum;
}
catch(Exception ex)
{
throw ex;
}
}
public void GetRemoteFile(ref ArrayList ArrL,string Path)
{
try
{
if(Path.Substring(Path.Length - 1,1) != @"\")
Path = Path + @"\";
string AddressIp = (GetTcpip()).ToString();
DirectoryInfo dirc = new DirectoryInfo(Path);
if(dirc.Exists)
{
foreach(FileInfo file in dirc.GetFiles())
{
ListViewProperty Lvp = new ListViewProperty();
Lvp.FName = file.Name;
Lvp.FSize = file.Length.ToString();
Lvp.AddIp = AddressIp;
Lvp.CreateTime = file.CreationTime.ToString();
Lvp.ChangeTime = file.LastAccessTime.ToString();
Lvp.SaveDir = file.DirectoryName;
Lvp.FileDir = file.FullName;
int Index = Lvp.SaveDir.LastIndexOf(@"\");
Lvp.FMachine= Lvp.SaveDir.Substring( Index + 1);
ArrL.Add(Lvp);
}
}
}
catch(Exception ex)
{
throw ex;
return ;
}
}
public void GetFileStream(ref StreamReader Sr,string Path)
{
try
{
FileInfo file = new FileInfo(Path);
if(file.Exists)
{
Sr = new StreamReader(Path);
}
}
catch(Exception ex)
{
throw ex;
}
}
{
try
{
if(SendPath.Substring(SendPath.Length - 1,1) != @"\")
SendPath = SendPath + @"\";
DirectoryInfo dirc = new DirectoryInfo(SendPath);
string DircSum = "";
if(dirc.Exists)
{
if(DisposeType)
{
foreach(DirectoryInfo Dic in dirc.GetDirectories())
{
if(DircSum == "")
DircSum = Dic.Name;
else
DircSum = DircSum + '|' + Dic.Name;
}
}
else
{
dirc.Delete(true);
DircSum = " ";
}
}
return DircSum;
}
catch(Exception ex)
{
throw ex;
}
}
public void GetRemoteFile(ref ArrayList ArrL,string Path)
{
try
{
if(Path.Substring(Path.Length - 1,1) != @"\")
Path = Path + @"\";
string AddressIp = (GetTcpip()).ToString();
DirectoryInfo dirc = new DirectoryInfo(Path);
if(dirc.Exists)
{
foreach(FileInfo file in dirc.GetFiles())
{
ListViewProperty Lvp = new ListViewProperty();
Lvp.FName = file.Name;
Lvp.FSize = file.Length.ToString();
Lvp.AddIp = AddressIp;
Lvp.CreateTime = file.CreationTime.ToString();
Lvp.ChangeTime = file.LastAccessTime.ToString();
Lvp.SaveDir = file.DirectoryName;
Lvp.FileDir = file.FullName;
int Index = Lvp.SaveDir.LastIndexOf(@"\");
Lvp.FMachine= Lvp.SaveDir.Substring( Index + 1);
ArrL.Add(Lvp);
}
}
}
catch(Exception ex)
{
throw ex;
return ;
}
}
public void GetFileStream(ref StreamReader Sr,string Path)
{
try
{
FileInfo file = new FileInfo(Path);
if(file.Exists)
{
Sr = new StreamReader(Path);
}
}
catch(Exception ex)
{
throw ex;
}
}