【发布时间】:2015-08-27 08:31:59
【问题描述】:
当 debug..Button1 是关于 zip 文件时会出现此错误,然后将其从源复制到目标..在删除功能中,它会删除创建时间早于给定时间的文件.. 注意:我是新手,所以如果可能的话,请在你的回答中提供很多细节。
private void button1_Click(object sender, EventArgs e)
{
Backup._MAIN takeBackUp = new Backup._MAIN();
try
{
takeBackUp.copyFile(textBox1.Text, textBox2.Text);
MessageBox.Show("done"); //do stuff
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button2_Click(object sender, EventArgs e)
{
bool dater;
string err = "";
Backup._MAIN formDelete = new Backup._MAIN();
DateTime dtp = dateTimePicker1.Value;
dater = formDelete.deleteFiles(textBox3.Text, dtp,out err);
if (err.Length > 0)
MessageBox.Show(err);
else
MessageBox.Show("Done!");
}
DLL:
public void copyFile(string sSource,string sDestination)
{
string sourcePath = sSource;
string targetPath = sDestination;
Directory.GetFiles(sourcePath,"",SearchOption.AllDirectories);
string myBackUp="";
string fileName;
if (!System.IO.Directory.Exists(targetPath))
{
System.IO.Directory.CreateDirectory(targetPath);
}
using (ZipFile zip = new ZipFile(targetPath))
{
zip.AddDirectory(sourcePath, "");
zip.Save(myBackUp);
}
if (System.IO.Directory.Exists(sourcePath))
{
string[] fileList = System.IO.Directory.GetFiles(sourcePath, "*.rar*");
foreach (string files in fileList)
{
// from the path.
fileName = System.IO.Path.GetFileName(files);
targetPath = System.IO.Path.Combine(targetPath, fileName);
System.IO.File.Copy(files, targetPath, true);
}
}
}
public bool deleteFiles(string sSource, DateTime dOlder, out string sError)
{
string path = sSource;
sError = "";
try
{
string[] fileList = Directory.GetFiles(path);
foreach ( string fname in fileList )
{
if ( File.GetCreationTime(path + fname) <= dOlder )
{
File.Delete(path + fname);
}
}
return true;
}
catch ( Exception ex )
{
sError = ex.ToString();
return false;
}
}
【问题讨论】:
-
它把乳液放在篮子里,或者它又得到软管。你能改写你的第一段,不知道你的意思
-
你能告诉我们实际的问题是什么吗?您刚刚发布了代码并解释了它的作用..
-
@MickyDuncan 现在我感觉像一些蚕豆
-
我更新了它...问题在标题中..路径不是合法形式...它们都给出相同的错误
-
我认为您的源路径不是合法形式 - 您应该重新格式化它以使其正确。如果您想要更有用的评论,请提供您正在使用的源路径。此外,设置断点并单步执行代码。