TheDarklord
March 12th, 2010, 07:13 AM
I have some code which searches for files and adds them to a list based on the individual filenames. Then it sorts out if there are any duplicate files based on the filename.
For example:
Song: "Bat out of hell" in folder one is the same as Song "Bat out of Hell" in folder two.
The code also adds files to another list called filelist2 on based on the file extension.
For example "C:My Documents\Music\Folder 1: Bat out of Hell.mp3" and "C:My Documents\Music\Folder 2: Bat out of Hell.mp3".
In this case, the filename extension is not the same because "folder 1" and "folder2 are not the same.
foreach (string foldername in Directory.GetDirectories(DirectoryName))
{
MP3Header mp3hdr = new MP3Header();
string Mp3Filename;
foreach (string filename in Directory.GetFiles(foldername))
{
string extension = Path.GetExtension(filename);
FileInfo f = new FileInfo(filename);
if (extension == FileTypeExtension)
{
this.listBox1.Items.Add(filename);
}
if (f.Length <= thisFileLength)
{
this.listBox2.Items.Add(filename);
}
// Form1 tag = new Form1();
bool boolIsMP3 = mp3hdr.ReadMP3Information(filename);
this.listBoxFileName.Items.Add(mp3hdr.strFileName);
this.listBox3.Items.Add(mp3hdr.lngFileSize.ToString());
this.listBoxBitRate.Items.Add(mp3hdr.intBitRate.ToString());
this.listBoxFrequency.Items.Add(mp3hdr.intFrequency.ToString());
this.listBoxstrMode.Items.Add(mp3hdr.strMode);
this.listBoxstrLength.Items.Add(mp3hdr.strLengthFormatted);
//Mp3Filename = filename;
Filelist.Add(mp3hdr.strFileName);
Filelist2.Add(filename);
//Filelist.Add(filename);
Filelist.Sort();
Filelist2.Sort();
}
}
for (int i = 1; i <= Filelist.Count - 1; i++)
{
if (Filelist[i].ToString() == Filelist[i - 1].ToString())
{
this.listBox4.Items.Add(Filelist[i].ToString());
this.listBox5.Items.Add(Filelist[i-1].ToString());
}
}
}
Is there any way of sorting filelist2 to be the same order as filelist1?
For example:
In flielist one:
1. Bat out of Hell
2. Bat out of Hell
3. Like a virgin
4. Like a virgin.
5. Born to run.
6. Born to run.
Then in filelist2
1. C:My Documents\Music\Folder1\Bat out of Hell
2. C:My Documents\Music\Folder2\Bat out of Hell
3. C:My Documents\Music\Folder1\Like a virgin
4. C:My Documents\Music\Folder2\Like a virgin.
5. C:My Documents\Music\Folder1\Born to run.
6. C:My Documents\Music\Folder2\Born to run.
For example:
Song: "Bat out of hell" in folder one is the same as Song "Bat out of Hell" in folder two.
The code also adds files to another list called filelist2 on based on the file extension.
For example "C:My Documents\Music\Folder 1: Bat out of Hell.mp3" and "C:My Documents\Music\Folder 2: Bat out of Hell.mp3".
In this case, the filename extension is not the same because "folder 1" and "folder2 are not the same.
foreach (string foldername in Directory.GetDirectories(DirectoryName))
{
MP3Header mp3hdr = new MP3Header();
string Mp3Filename;
foreach (string filename in Directory.GetFiles(foldername))
{
string extension = Path.GetExtension(filename);
FileInfo f = new FileInfo(filename);
if (extension == FileTypeExtension)
{
this.listBox1.Items.Add(filename);
}
if (f.Length <= thisFileLength)
{
this.listBox2.Items.Add(filename);
}
// Form1 tag = new Form1();
bool boolIsMP3 = mp3hdr.ReadMP3Information(filename);
this.listBoxFileName.Items.Add(mp3hdr.strFileName);
this.listBox3.Items.Add(mp3hdr.lngFileSize.ToString());
this.listBoxBitRate.Items.Add(mp3hdr.intBitRate.ToString());
this.listBoxFrequency.Items.Add(mp3hdr.intFrequency.ToString());
this.listBoxstrMode.Items.Add(mp3hdr.strMode);
this.listBoxstrLength.Items.Add(mp3hdr.strLengthFormatted);
//Mp3Filename = filename;
Filelist.Add(mp3hdr.strFileName);
Filelist2.Add(filename);
//Filelist.Add(filename);
Filelist.Sort();
Filelist2.Sort();
}
}
for (int i = 1; i <= Filelist.Count - 1; i++)
{
if (Filelist[i].ToString() == Filelist[i - 1].ToString())
{
this.listBox4.Items.Add(Filelist[i].ToString());
this.listBox5.Items.Add(Filelist[i-1].ToString());
}
}
}
Is there any way of sorting filelist2 to be the same order as filelist1?
For example:
In flielist one:
1. Bat out of Hell
2. Bat out of Hell
3. Like a virgin
4. Like a virgin.
5. Born to run.
6. Born to run.
Then in filelist2
1. C:My Documents\Music\Folder1\Bat out of Hell
2. C:My Documents\Music\Folder2\Bat out of Hell
3. C:My Documents\Music\Folder1\Like a virgin
4. C:My Documents\Music\Folder2\Like a virgin.
5. C:My Documents\Music\Folder1\Born to run.
6. C:My Documents\Music\Folder2\Born to run.