【发布时间】:2014-06-25 22:39:17
【问题描述】:
我正在编写一个程序,它应该读出 mp3 文件的 id3 标签,创建一个以艺术家命名的目录,然后我想将 mp3 文件移动到特定的艺术家目录中。
当我尝试移动 Mp3 文件时,它不会将它移动到我创建的音乐目录的子文件夹(命名为艺术家)中。 我只想移动 Mp3 文件,而不是重命名它们。
这是我的代码:
public void moveFiles(string path, string[] title, string[] artist,string [] songs)
{//loop through the title array
for(int i=0;i<title.Length;i++)
{// no artist no name
if (artist[i] == null)
{
i += 1;
}//check if sourceFile is existing
if (File.Exists(songs[i]))
{//check if destinationFile is existing
if (File.Exists((@"C:\Musik\" + artist[i] + songs[i])))
{//if delete
File.Delete((@"C:\Musik\" + artist[i] + songs[i]));
}
else
{ //move file from songs[i](sourcePath)to (destinationPath)
File.Move(songs[i],(@"C:\Musik\" + artist[i] + songs[i]));
MessageBox.Show("Das Lied " + title[i] + " wurde erfolgreich verschoben");
}
}
else
{
MessageBox.Show(songs[i]+" does not exist!");
}
}
}
它只会将我的文件移动到 C:\Musik 目录中,它会像 Artist-Song 一样重命名我的文件; 欢迎任何帮助。 谢谢:)
【问题讨论】:
-
提示:您不需要
File.Exists。If the file to be deleted does not exist, no exception is thrown.还有一个:使用i++而不是i += 1