#include "hx.h"
deal_mp3::deal_mp3(TCHAR* DirectoryPath,TCHAR operation,TCHAR* DirMp3Store)
{
this->DirectoryPath = new TCHAR[MAX_PATH];
this->operation = operation;
this->DirMp3Store = new TCHAR[MAX_PATH];
this->DirectoryTemp = new TCHAR[MAX_PATH];
lstrcpy(this->DirectoryPath,DirectoryPath);
lstrcpy(this->DirMp3Store,DirMp3Store);
if (this->operation == 'S')
{
this->StartSearch();
}
else if (this->operation == 'C')
{
this->ReadWma();
}
}
deal_mp3::~deal_mp3()
{
delete[] this->DirectoryPath;
delete[] this->DirMp3Store;
delete[] this->DirectoryTemp;
}
void deal_mp3::Printback()
{
system("cls");
}
void deal_mp3::StartSearch()
{
CreateDirectory(this->DirMp3Store, NULL);//建立存放MP3的暂时文件夹
WIN32_FIND_DATA stFnd = {0};
wstring DirStart(this->DirectoryPath);
this->Directory_queue.push(DirStart);
while (this->Directory_queue.empty() != TRUE)
{
wstring DirTemp((wstring)this->Directory_queue.front());
this->Directory_queue.pop();
if (lstrlen(DirTemp.c_str()) == 0)
{
printf("the string is with nothing\n");
continue;
}
memset(this->DirectoryTemp,0,MAX_PATH*2);
lstrcpy(this->DirectoryTemp,DirTemp.c_str());
TCHAR DireSearch[MAX_PATH] = {0};
this->AddFileSpec(DireSearch);
if (lstrlen(DireSearch) == 0)
{
continue;
}
HANDLE hFind = FindFirstFile(DireSearch,&stFnd);
if (hFind == INVALID_HANDLE_VALUE)
{
this->Printback();
wprintf(_TEXT("search %s error\n"),DireSearch);
continue;
}
do
{
if (stFnd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)//文件夹目录
{
if (stFnd.cFileName[0] == 0x002e)//是"."和"..";
{
//什么也不做
}
else
{
this->DirectoryDeal(stFnd.cFileName);//文件夹目录放进队列里
}
}
else//是文件
{
if (this->TellExtension(stFnd.cFileName))
{
this->FileDeal(&stFnd);
}
}
memset(&stFnd, 0, sizeof(stFnd));
} while (FindNextFile(hFind, &stFnd));
FindClose(hFind);
}
}
BOOL deal_mp3::TellExtension(TCHAR* FileName)
{
TCHAR* szExtent = PathFindExtension(FileName);
if (szExtent != NULL)
{
int cmp1 = lstrcmpi(szExtent, _TEXT(".mp3"));
int cmp2 = lstrcmpi(szExtent, _TEXT(".wma"));
int cmp3 = lstrcmpi(szExtent, _TEXT(".wav"));
if (!cmp1 || !cmp2 || !cmp3 )
{
return TRUE;
}
}
return FALSE;
}
void deal_mp3::AddFileSpec(TCHAR* PathTemp)
{
if (PathTemp == NULL)
{
return;
}
PathCombine(PathTemp, this->DirectoryTemp, _TEXT("*.*"));
}
void deal_mp3::DirectoryDeal(TCHAR* DirectoryTemp)
{
TCHAR DirectoryStore[MAX_PATH] = {0};
PathCombine(DirectoryStore,this->DirectoryTemp,DirectoryTemp);
this->Printback();
wprintf(_TEXT("%s"),DirectoryStore);
wstring Director_wst(DirectoryStore);
this->Directory_queue.push(Director_wst);//文件夹目录放进队列里
}
BOOL deal_mp3::FileDeal(WIN32_FIND_DATA* pstFnd)
{
if (pstFnd == NULL)
{
wprintf(_TEXT("the win32_find_data pointer is null\n"));
return FALSE;
}
if (pstFnd->nFileSizeLow<=(3*1024*1024))//如果没有超过3M的大小
{
return TRUE;
}
TCHAR FullPathSource[MAX_PATH] = {0};
TCHAR FullPathDest[MAX_PATH] = {0};
PathCombine(FullPathSource,this->DirectoryTemp,pstFnd->cFileName);//绝对路径FullPathSource
PathCombine(FullPathDest,this->DirMp3Store,pstFnd->cFileName);//绝对路径FullPathDest
this->Printback();
wprintf(L"copy the file: %s",FullPathSource);
if (CopyFile(FullPathSource,FullPathDest,FALSE) == 0)
{
wprintf(_TEXT("copy file: %s error\n"),FullPathSource);
return FALSE;
}
PathRenameExtension(FullPathDest,L".info");//修改后辍名为.info
BOOL RetValue = this->CreateMp3InfoFile(FullPathDest,FullPathSource);
return RetValue;
}
BOOL deal_mp3::CreateMp3InfoFile(TCHAR* PathInfoFile,TCHAR* InfoToBeWriteen)
{
HANDLE hFile = CreateFile(PathInfoFile,GENERIC_WRITE,\
FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
wprintf(_TEXT("open or create file %s error\n"),PathInfoFile);
return FALSE;
}
SetFilePointer(hFile,0,0,FILE_END);
int ByteToWrite = lstrlen(InfoToBeWriteen)*sizeof(TCHAR);
DWORD ByteWritten = 0;
BOOL ExValue = WriteFile(hFile,InfoToBeWriteen,ByteToWrite,&ByteWritten,NULL);
if (ExValue == FALSE)
{
wprintf(_TEXT("write file: %s error\n"),PathInfoFile);
CloseHandle(hFile);
return FALSE;
}
WriteFile(hFile,_TEXT("\r\n"),4,&ByteWritten,NULL);
CloseHandle(hFile);
return TRUE;
}
没有合适的资源?快使用搜索试试~ 我知道了~
用windows文件操作处理目录下很多的音乐文件
共6个文件
cpp:3个
h:1个
dsp:1个
需积分: 9 8 下载量 181 浏览量
2011-04-11
10:03:15
上传
评论
收藏 6KB RAR 举报
温馨提示
用windows文件操作处理目录下很多的音乐文件 相信大家都碰到这样的情况,在你的音乐文件夹下有很多音乐文件,有些音乐文件体积很大,你很想把它们一一压缩转换为体积较小的wma格式的,但是苦于目录太多,音乐文件到处放,手动去找很麻烦,因此,基于WINDOWS下的文件操作,我用C++写了一个这样的处理过程,拿出来和大家分享 说明,程序只是把你的目录中所有大于3M的音乐文件找出来,复制到一个另外目录下,转换还得手动去转换,你可以把这些音乐文件一起拖到千千静听转换!! 转换后用程序即可把转换后的wma文件复制回原来的音乐目录下。
资源推荐
资源详情
资源评论
收起资源包目录
deal_mp3.rar (6个子文件)
deal_mp3.dsp 4KB
deal_mp3.dsw 522B
read_wma.cpp 3KB
hx.h 2KB
search_mp3.cpp 4KB
deal_mp3.cpp 1KB
共 6 条
- 1
资源评论
遇见恒星
- 粉丝: 18
- 资源: 71
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功