点击path/TempFolder
后我在AddButton
中有了一些图片我想逐个更改其位置path/Images
并更改其名称
任何想法?
答案 0 :(得分:1)
MS有一些关于如何实现这一目标的文档。您是否尝试过提交的解决方案here?
编辑:我已经从网站复制了SampleMove功能,以供将来的后代使用。
// Simple synchronous file move operations with no user interface.
public class SimpleFileMove
{
static void Main()
{
string sourceFile = @"C:\Users\Public\public\test.txt";
string destinationFile = @"C:\Users\Public\private\test.txt";
// To move a file or folder to a new location:
System.IO.File.Move(sourceFile, destinationFile);
// To move an entire directory. To programmatically modify or combine
// path strings, use the System.IO.Path class.
System.IO.Directory.Move(@"C:\Users\Public\public\test\", @"C:\Users\Public\private");
}
}
答案 1 :(得分:1)
您可以使用File.Move
(msdn)方法:
foreach (var item in System.IO.Directory.GetFiles(@"C:\TempFolder"))
{
string name = new System.IO.FileInfo(item).Name;
string newName = name.Insert(name.IndexOf("."), "_new");
System.IO.File.Move(item, System.IO.Path.Combine(@"C:\Images", newName));
}