它調試時發出此錯誤.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;
}
}
_IT把乳液在籃下也得到軟管again_你能改寫你的第一款,不知道你是什麼意思 – MickyD
你能告訴我們真正的問題是什麼?你只是張貼代碼,並解釋它是什麼.. – Rob
@MickyDuncan現在我覺得像一些蠶豆 –