C# 如何将图像的路径位置从一个文件夹更改为另一个文件夹
单击C# 如何将图像的路径位置从一个文件夹更改为另一个文件夹,c#,asp.net,C#,Asp.net,单击add按钮后,我在path/TempFolder中有一些图片,我想将它们的位置逐个更改为path/Images,并更改它们的名称 有什么想法吗?MS有一些关于如何实现这一点的文档。您是否尝试过提出的解决方案 编辑:我已经从网站上复制了SampleMove功能,以供将来使用 // Simple synchronous file move operations with no user interface. public class SimpleFileMove { static vo
add按钮后,我在path/TempFolder
中有一些图片,我想将它们的位置逐个更改为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
()方法:
你试过什么吗?一些代码示例会很好..是的,我已经搜索过了,但他们中的大多数人都在谈论仅更改文件名我找到了此链接,但搜索“C#move file”对我不起作用!谷歌是你的朋友。听起来不错,我要找的是复制图像文件并删除以前的文件
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));
}