string dpath="目标文件夹路径"
if(Directory.Exist(path))
{
string[] files = Directory.GetFiles(path, "*.doc",
System.IO.SearchOption.AllDirectories)
foreach(string str in files)
{
FileInfo info=new FileInfo(str)
//省略目录及文件是否存在的判断
info.MoveTo(dpath)
}
}
但需要注意目录的权限。
给你个例子:public Form1()
{
InitializeComponent()
this.AllowDrop = true
this.DragEnter += new DragEventHandler(Form1_DragEnter)
this.DragDrop += new DragEventHandler(Form1_DragDrop)
}
void Form1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.All
}
else
{
e.Effect = DragDropEffects.None
}
}
void Form1_DragDrop(object sender, DragEventArgs e)
{
// 这里写你要处理的代码。
}
给你个例子,代码比较乱,凑合看看吧string path = @"c:\temp\MyTest.txt"
string path2 = @"c:\temp2\MyTest.txt"
try
{
if (!File.Exists(path))
{
throw new Exception("file not exist")
}
// Ensure that the target does not exist.
if (File.Exists(path2))
File.Delete(path2)
// Move the file.
File.Move(path, path2)
Console.WriteLine("{0} was moved to {1}.", path, path2)
// See if the original exists now.
if (File.Exists(path))
{
Console.WriteLine("The original file still exists, which is unexpected.")
}
else
{
Console.WriteLine("The original file no longer exists, which is expected.")
}
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString())
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)