如何将图像的路径位置从一个文件夹更改为另一个文件夹
本文关键字:文件夹 一个 另一个 图像 路径 位置 | 更新日期: 2023-09-27 18:28:56
我在path/TempFolder
中有一些图片,单击AddButton
后,我想将它们的位置逐个更改为path/Images
并更改它们的名称知道吗?
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");
}
}
您可以使用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));
}