和作者私信沟通了一下确定了需求,更新代码如下:
using System.Collections.Generic; using System.IO; using System.Linq; namespace Question1 { class Program { static void Main(string[] args) { //你的U盘盘符 string dest = @"H:\"; //先复制收藏的那一部分 foreach (var file in GetFavorites()) { File.Copy(file, dest + file.Replace("+", "").Split(\\).Last()); } //再复制没收藏的剩下那部分 foreach (var file in GetOthers()) { File.Copy(file, dest + file.Split(\\).Last()); } } public static List<string> GetFavorites() { List<string> result = new List<string>(); foreach (var dir in Directory.GetDirectories(Directory.GetCurrentDirectory())) { result.AddRange( from file in Directory.GetFiles(dir) where file.Split(\\).Last().StartsWith("+") select file ); } return result; } public static List<string> GetOthers() { List<string> result = new List<string>(); foreach (var dir in Directory.GetDirectories(Directory.GetCurrentDirectory())) { result.AddRange( from file in Directory.GetFiles(dir) where !file.Split(\\).Last().StartsWith("+") select file ); } return result; } } }在VS中点击文件→新建→项目→Visual C#项目→控制台应用程序,把代码完整的复制进去,把盘符改成你自己的U盘盘符,编译后在项目文件夹→bin→Debug下找到exe,移动到音乐文件夹的根目录下(就是和你说的ABCDE文件夹平层),运行即可。
要求是不能有同名文件,否则会报错。
有不懂的地方再问我
接楼上,Python版,没有测试过
import shutil import os base_path = r"E:/" # 源文件位置 target_path = r"F:/" # 目标U盘位置 file_name_list = ["1","2","3","4","5","6","7","8"] # 文件名列表 folder_name_list = ["A","B","C","D","E","F","G","H","I"] # 目录名列表 for file_name in file_name_list: for folder_name in folder_name_list: shutil.copy(base_path + folder_name + os.pathsep + file_name +".mp3", target_path + folder_name + file_name + ".mp3")