using Shell32;
using System.IO;
<span style="line-height: 24px; font-family: monospace; font-size: 14px; text-align: left; white-space: pre-wrap; background-color: rgb(204, 206, 208); margin: 0px; padding: 0px; color: rgb(0, 128, 0); ">//</span><span style="line-height: 24px; font-family: monospace; font-size: 14px; text-align: left; white-space: pre-wrap; background-color: rgb(204, 206, 208); margin: 0px; padding: 0px; color: rgb(0, 128, 0); ">添加引用:COM组件的 Microsoft Shell Controls And Automation</span>
namespace 批量获取mp3文件名及时长
{
class Program
{
static void Main(string[] args)
{
string[] fn = Directory.GetFiles(@"G:\录音\2011\201112\20111201");
string[] names = new string[fn.Length];
for (int i = 0; i < fn.Length; i++)
//foreach (string file in fn)
{
//string file = @"E:\luyin\浣犳槸鎴戝唴蹇冪殑涓€棣栨瓕.mp3";
ShellClass sh = new ShellClass();
Folder dir = sh.NameSpace(Path.GetDirectoryName(fn[i].ToString()));
FolderItem item = dir.ParseName(Path.GetFileName(fn[i].ToString()));
string str = fn[i].ToString() + "," + dir.GetDetailsOf(item, 21); //
//string[] names = new string[fn.Length];
//for (int i = 0; i < fn.Length; i++)
//{
names[i] = str;
//}
Console.WriteLine(str);
}
StreamWriter sw = File.AppendText(@"G:\testing3.txt");
foreach (string ly in names)
{
sw.WriteLine(ly);
}
sw.Flush();
sw.Close();
Console.ReadLine();
}
}
}
<span style="margin: 0px; padding: 0px; font-family: 'Courier New'; line-height: 1.8; ">// 如果执行过程中,出现是错误提示,通过</span><span style="margin: 0px; padding: 0px; font-family: 'Courier New'; line-height: 1.8; ">Shell32 的 </span><span style="margin: 0px; padding: 0px; font-family: 'Courier New'; line-height: 1.8; ">Embed Interop Types 属性设置为 False 即可;</span>