编程批量删除MP3文件的附加信息

源码:

  1 //---------------------------------------------------------------------------
  2 
  3 #include 
  4 #pragma hdrstop
  5 
  6 #include "Unit1.h"
  7 //---------------------------------------------------------------------------
  8 #pragma package(smart_init)
  9 #pragma resource "*.dfm"
 10 TForm1 *Form1;
 11 //---------------------------------------------------------------------------
 12 __fastcall TForm1::TForm1(TComponent* Owner)
 13         : TForm(Owner)
 14 {
 15 }
 16 //---------------------------------------------------------------------------
 17 void __fastcall TForm1::Button1Click(TObject *Sender)
 18 {
 19     if(OpenDialog1->Execute())
 20     {
 21         //OpenDialog1->Options.Clear();
 22         //OpenDialog1->Options << ofAllowMultiSelect << ofFileMustExist;
 23 
 24         int count = OpenDialog1->Files->Count;
 25         TStringList *files = new TStringList;
 26         files->Assign(OpenDialog1->Files);
 27 
 28         for(int i=0;i)
 29         {
 30             ClearFileInfo(files->Strings[i]);
 31             Memo1->Lines->Add(files->Strings[i]);
 32         }
 33     }
 34     ShowMessage("文件修改完成。");
 35 }
 36 //---------------------------------------------------------------------------
 37 void __fastcall TForm1::ClearFileInfo(String fileName)
 38 {
 39         int fileHandle;
 40         int fileLength;
 41         unsigned int readLength;
 42         char *buffer;
 43         
 44         fileHandle = FileOpen(fileName,fmOpenReadWrite);
 45         fileLength = FileSeek(fileHandle,0,2);
 46         FileSeek(fileHandle,0,0);
 47         buffer = new char[fileLength+1];
 48         readLength = FileRead(fileHandle,buffer,fileLength);
 49 
 50         if(buffer[0]!='I' || buffer[1]!='D' || buffer[2]!='3')
 51         {
 52            ShowMessage("不是ID3 v1格式文件。");
 53            return;
 54         }
 55         //如果是 2.3版本,就把后面的0xF0字节清零
 56         if(buffer[3]==0x03)
 57         {
 58             for(int i=0;i<0xf0;i++)
 59             {
 60                 buffer[4+i] = '\0';
 61             }
 62         }
 63 
 64         int tmp = fileLength - 128;
 65         if(String(buffer[tmp])!='T' ||String(buffer[tmp+1])!='A' ||String(buffer[tmp+2])!='G')
 66         {
 67             ShowMessage("没有找到‘TAG’标志。");
 68             return;
 69         }
 70         tmp += 3;
 71         for(int i=0;i<125;i++)
 72         {
 73             buffer[tmp+i] = '\0';
 74         }
 75         FileSeek(fileHandle,0,0);
 76         readLength = 0;
 77         readLength = FileWrite(fileHandle,buffer,fileLength);
 78         if(readLength == -1)
 79         {
 80             ShowMessage("写入失败!");
 81             return;
 82         }
 83 
 84         
 85         /*
 86         char drive[MAXDRIVE];         //驱动器名
 87         char dir[MAXDIR];             //目录,包括前后反斜杠
 88         char file[MAXFILE];          //文件主名
 89         char ext[MAXEXT];            //文件扩展名,包括前面的 点
 90         int flags;
 91 
 92 
 93         String s = OpenDialog1->FileName;
 94         flags=fnsplit(s.c_str(),drive,dir,file,ext);
 95         if(flags & FILENAME)
 96         {
 97             s= String(file);      //主文件名
 98         }
 99         */
100         FileClose(fileHandle);
101         delete [] buffer;     
102 }
103 //---------------------------------------------------------------------------

 

转载于:https://www.cnblogs.com/lanlong2000/p/7987850.html

你可能感兴趣的:(编程批量删除MP3文件的附加信息)