c# - C#将列表框中列出的项目移动到另一个文件夹中
问题描述
谢谢您的帮助!我一直在尝试将文件名列出到列表框中,并将列表框中列出的文件移动到另一个文件夹中,但我做不到。我已经了解了如何将文件列出到 Listbox 中,但我唯一被困在这里的是我无法将列出的项目从一个文件夹移动到另一个文件夹。
这是我将列出的项目移动到另一个文件夹的代码。
string sourcePath = @"C:\Users\Business\Music\Example\\";
string targetPath = @"C:\Users\Business\Music\SENT\";
if (!Directory.Exists(targetPath))
{
Directory.CreateDirectory(targetPath);
}
string[] sourcefiles = Directory.GetFiles(listBox2.Items.ToString());
foreach (string sourcefile in sourcefiles)
{
string fileName = Path.GetFileName(sourcefile);
string destFile = Path.Combine(targetPath, fileName);
File.Copy(sourcefile, destFile, true);
}
解决方案
推荐阅读
- javascript - CreateJS(画布)Iframe
- microservices - Cumulocity:将二进制文件添加到微服务错误
- ios - 应用程序未显示在任何 iPhone 的外部显示扩展中
- php - 数据未存储在 PHP 站点的 mysql 数据库表中
- angular - Angular 单元测试模拟 paramMap 获取
- arrays - Pass array of arrays (or slice of slices) in Rust
- ios - 表格视图中的 iOS 图表:正确使用委托和全局缩放
- r - how to duplicate rows by condition and replace content in R
- android - Save Image in External Storage By using Picasso from Url , how to download image and show it in imageview
- python - Problem interpreting a "while loop" notation in Python