如何把找到的.txt文件批量移动到电脑中
解决方案 »
- SQL问题 进来看看
- 打印分页,多线程
- C#datagridview里可以添加附件吗 .
- vs2005用哪种exception捕获参数异常
- 哪位大哥有自定义的日期控件?C#写的!谢谢!!!
- 在.net平台下,在IE浏览器中使用Windows窗体控件对客户端访问权限的问题?
- ParentGridView.Rows[i].Cells[id_index].Text 取不到值的问题
- 如何阻塞调用 System.IO.File.Copy
- 我刚学C#没有什么基础,你说我该怎样学呀
- 请问在DATAGRID中可以获取选定列的索引吗??
- ClientScript.RegisterStartupScript中斜杠的问题
- 【顶也给分的。】如何让iis可以和nginx一样支持flv视频的视频流的切割那个呀.谢谢了.
将指定文件移到新位置,并提供指定新文件名的选项
using System;
using System.IO;class Test
{
public static void Main()
{
string path = @"c:\temp\MyTest.txt";
string path2 = @"c:\temp2\MyTest.txt";
try
{
if (!File.Exists(path))
{
// This statement ensures that the file is created,
// but the handle is not kept.
using (FileStream fs = File.Create(path)) {}
} // 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());
}
}
}
int i=0;
foreach(string file in files)
{
File.Move(file,newfilepath+(i++).ToString());
}
int i=0;
foreach(string file in files)
{
File.Move(file,newfilepath+(i++).ToString());
}