#include
#include
#include
#include
#include
#define MAX_PATH 50
#define MAX_KEYWORD 50
#define PATH strcpy(file_path, "D:\\我的文档\\My Music\\英文\\blue")
_Bool leach_file(char *file_path);
int get_keyword(char *s, char *keyword);
_Bool search_list(char *keyword);
int main(void)
{
char file_path[MAX_PATH];
printf("请输入歌曲路径(如:d:\\mp3):");
fgets(file_path, MAX_PATH-4, stdin);
file_path[strlen(file_path) - 1] = '\0';
//PATH;
chdir(file_path); // 改变当前路径为歌曲目录
strcat(file_path, "\\*.wma");
if (leach_file(file_path) == false)
puts("没有重复的歌曲!");
getch();
return 0;
}
_Bool leach_file(char *file_path)
{
struct _finddata_t file_ptr; // 存放当前的文件名
char keyword[MAX_KEYWORD];
long f; // 句柄
_Bool flag = false; // 是否有重复歌曲
if ((f = _findfirst(file_path, &file_ptr)) == -1)
exit(0);
printf("重复的歌曲列表:\n");
while (_findnext(f, &file_ptr) != -1) {
get_keyword(file_ptr.name, keyword);
if (search_list(keyword) == true) { // 检索歌曲,如有重复则删除
puts(file_ptr.name);
printf("确认删除?:");
if (getch() == 'y') {
if (remove(file_ptr.name) == 0)
puts("\n删除成功...");
}
else
puts("放弃删除...");
flag = true;
}
}
return flag;
}
int get_keyword(char *s, char *keyword)
{
int i, j;
bool flag;
i = j = 0;
while (s[i] && ('-' != s[i++]))
continue;
flag = (s[i] < 0)? true:false; // 针对中文歌曲的特别处理
while ((i < FILENAME_MAX) && (j < MAX_KEYWORD-1)) {
if (' ' == s[i] && flag == true)
break;
else if (' ' == s[i])
flag = true;
else if ('(' == s[i] || '-' == s[i] || '.' == s[i])
break;
keyword[j++] = s[i++];
}
keyword[j] = '\0';
return 0;
}
typedef struct keys {
char key[MAX_KEYWORD];
struct keys *next;
}*KEY;
_Bool search_list(char *keyword)
{
static KEY head = NULL, ptr, last, n;
if (NULL == head) { // 创建第一个关键字
if ((head = (KEY)malloc(sizeof(struct keys))) == NULL)
exit(0);
strcpy(head->key, keyword);
head->next = NULL;
return false;
}
last = ptr = head;
while (ptr != NULL) {// 检索关键字表
if (!strcmp(ptr->key, keyword))
return true;
last = ptr;
ptr = ptr->next;
}
// 没有找到重复歌曲,则在表尾插入
if ((n = (KEY)malloc(sizeof(struct keys))) == NULL)
exit(0);
strcpy(n->key, keyword);
n->next = NULL;
last->next = n;
return false;
}
阅读(493) | 评论(0) | 转发(0) |