0

path/TempFolder点击后我有一些图片AddButton我想一一更改他们的位置path/Images并更改他们的名字知道吗?

4

2 回答 2

1

您可以使用File.Movemsdn)方法:

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));
}
于 2013-08-24T12:04:01.313 回答
1

MS 有一些关于如何实现这一点的文档。您是否尝试过这里介绍的解决方案?

编辑:我已经从该站点复制了 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");
    }
}
于 2013-08-24T12:00:53.200 回答