• 根据txt文件中指定的文件名进行文件分类


    根据txt文件中指定的文件名进行文件分类:

    // 根据txt文件中指定的文件名进行文件分类
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <malloc.h>
    #include <windows.h>
    #include <io.h>
    #include <direct.h>
    #include <string.h>
    
    void Remove_End_Char(char a[])
    {
        int L = strlen(a);
        for (int i = 0; i <= L; i++)
        if (a[i] == '
    ')
        {
            a[i] = '';
        }
    }
    
    char* Str_join(char *s1, char *s2)
    {
        char *result = (char *)malloc(strlen(s1) + strlen(s2) + 1); 
        
        if (result == NULL)
            exit(1);
    
        strcpy(result, s1);
        strcat(result, s2);
    
        return result;
    }
    
    
    int main()
    {
    
        char filename[] = "E:\name.txt";
        FILE *fp;
        char StrLine[260];
    
        if ((fp = fopen(filename, "r")) == NULL)
        {
            printf("open file error!");
            return -1;
        }
    
    
        long Handle;
        struct _finddata_t FileInfo;
    
        int Same_num = 0;
        char *New_Picture_File;
    
        // 需要修改
        _chdir("E:\");
    
        if ((Handle = _findfirst("*.jpg", &FileInfo)) == -1L)
        {
            printf("没有找到匹配的文件
    ");
        }
        else
        {
    
            while (!feof(fp))
            {
                fgets(StrLine, 260, fp);
                 Remove_End_Char(StrLine);
    
                // 文件名相同
                if (!strcmp(FileInfo.name, StrLine))
                {
                    printf("%s
    ", StrLine);
                    Same_num++;
    
                    // 需要修改
                    New_Picture_File = Str_join("E:\", StrLine);
                    rename(StrLine, New_Picture_File);
    
                }
    
            }
    
            // 重置文件指针指向文件头部
            rewind(fp);
            while (_findnext(Handle, &FileInfo) == 0)
            {
                while (!feof(fp))
                {
                    fgets(StrLine, 260, fp);
                    Remove_End_Char(StrLine);
    
                    // 文件名相同
                    if (!strcmp(FileInfo.name, StrLine))
                    {
                        printf("%s
    ", StrLine);
                        Same_num++;
    
                        // 需要修改
                        New_Picture_File = Str_join("E:\", StrLine);
                        rename(StrLine, New_Picture_File);
    
                        // 这两个都无法使用,参数还没匹配好
                        //system("copy    ");
                        //CopyFile(    );
                        
                    }
    
                }
                rewind(fp);
    
            }
        
        }
        printf("相同图片的数量是: %d
    ", Same_num);
    
    
        fclose(fp);
        _findclose(Handle);
    
        return 0;
    
    }
  • 相关阅读:
    从贫困生到创业者
    招聘会技巧:应聘外企的英语提问清单
    智能客户端(SmartClient)
    GOOGLE 技巧
    值得珍藏
    三个大学生开软件公司 毕业前挣300万
    卡车运输业中的无线技术
    莫扎特金色的童年和少年
    开放源码 ERP
    人才招聘站点大全
  • 原文地址:https://www.cnblogs.com/ht-beyond/p/5245263.html
Copyright © 2020-2023  润新知