ZIPU盘爬虫-自定义爬取文件类型 1.07MB

Server65535需要积分:5(1积分=1元)

资源文件列表:

U盘爬虫.zip 大约有3个文件
  1. U盘爬虫.exe 167.5KB
  2. U盘爬虫Setup.msi 1.19MB
  3. MainFile.cpp 6.28KB

资源介绍:

通过C/C++,WindowsAPI中的函数实现U盘拔插判断,U盘文件扫描,并根据实际需求爬取自定义的文件类型。 压缩包内包含3个文件: MainFile.cpp :源代码(可修改,需要安装easyx库在VS中调试) U盘爬虫.exe :主程序(需要特定静态库可运行) U盘爬虫Setup.msi :安装包(安装后可直接运行) 特别提示:请将小程序用于合法途径 源代码包含头文件: #include #include #include #include
#include <iostream> #include <Windows.h> #include <easyx.h> #include <string> #define screenw 540 #define screenh 360 using namespace std; char copyPath[500] = { 0 }; void quesout(int x, int y, int w, int h, string text, int way, int rightway, int* hangs) { LOGFONT f; gettextstyle(&f); settextstyle(h, w, f.lfFaceName); int size = text.size(); int cw = 0; int xs = x; for (int i = 0; i < size; i++) { if (xs + w >= screenw - rightway || (text[i] == ' ' && text[i + 1] == ' ')) { if (text[i] == ' ' && text[i + 1] == ' ') i += 2; xs = x; cw++; } if (text[i] <= 127 && text[i] > 0) { char str[10]; str[0] = text[i]; str[1] = '\0'; outtextxy(xs, y + cw * (h + way), str); xs += w; } else { char str[10]; str[0] = text[i]; str[1] = text[i + 1]; str[2] = '\0'; outtextxy(xs, y + cw * (h + way), str); xs += w * 2; i++; } } if (hangs != NULL) *hangs = cw + 1; } void textout(const char* text, int w, int h, int can) { settextstyle(h, w, "宋体"); size_t a = strlen(text); if (can == 0) outtextxy(5, 5, text); if (can == 1) outtextxy(screenw - a * w - 5, 5, text); if (can == 2) outtextxy(5, screenh - h - 5, text); if (can == 3) outtextxy(screenw - a * w - 5, screenh - h - 5, text); } void doubkeToString(double val, char* buf) { int i = 0; /**<目标buf下标 */ int j = 0; /**<源下标str下标 */ int point, sign; /**<point是小数点的位置,sign=1为负数且point<0 */ char* str = ecvt(val, 16, &point, &sign); if (point <= 0) { /**<小于1的数*/ /**<为负数,需要加上负号 */ if (sign == 0) { buf[i++] = '0'; buf[i++] = '.'; } else { buf[i++] = '-'; buf[i++] = '0'; buf[i++] = '.'; } point = -point; while (point--) /**<0.0000xxx模式 */ buf[i++] = '0'; while (i < 15 && str[j] != '0') /**<拷贝剩余数据,去除后面的0 */ buf[i++] = str[j++]; } else { /**<大于1的数*/ if (sign == 1) { buf[i++] = '-'; } while (j < point) /**<开始copy */ buf[i++] = str[j++]; buf[i++] = '.'; /**<添加小数点 */ int pointI = i; int isAllZero = 1; while (i < 15 && (isAllZero || str[j] != '0')) { /**<拷贝剩余位数,去除后面的0,前面的0要保留,-100.0001000 */ if (str[j] != '0') isAllZero = 0; buf[i++] = str[j++]; } if (isAllZero) { /**<100.0000000 */ buf[pointI + 1] = '\0'; } } } enum speedstyle { B, KB, MB, GB }; void print(char* path, unsigned long long speed) { BeginBatchDraw(); cleardevice(); int line, linelen = 5; outtextxy(5, 5, "正在爬取:"); quesout(5, 25, 8, 16, path, linelen, 5, &line); long double speedd = speed; speedstyle style = B; if (speed >= 1000) { style = KB; speedd /= 1000.0; } if (speed >= 1000000) { style = MB; speedd /= 1000.0; } if (speed>= 1000000000) { style = GB; speedd /= 1000.0; } char strspeed[32] = { 0 }; sprintf(strspeed, "%.2f", speedd); speed = 0; outtextxy(5, 26 + line * (16 + linelen), "爬取速度: "); outtextxy(85, 26 + line * (16 + linelen), &strspeed[0]); switch (style) { case B: outtextxy(85 + strlen(strspeed) * 8, 26 + line * (16 + linelen), " B/s"); break; case KB: outtextxy(85 + strlen(strspeed) * 8, 26 + line * (16 + linelen), " KB/s"); break; case MB: outtextxy(85 + strlen(strspeed) * 8, 26 + line * (16 + linelen), " MB/s"); break; case GB: outtextxy(85 + strlen(strspeed) * 8, 26 + line * (16 + linelen), " GB/s"); break; } EndBatchDraw(); } unsigned long long time1 = GetTickCount(), filesize = 0, speed = 0; void FindFile(const char* FileName) { WIN32_FIND_DATA FindData; char tempPath[500] = { 0 }; sprintf(tempPath, "%s\\*.*", FileName); HANDLE hfile = FindFirstFile(tempPath, &FindData); while (true) { if (FindData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY) { if (FindData.cFileName[0] != '.') { sprintf(tempPath, "%s\\%s", FileName, FindData.cFileName); FindFile(tempPath); } } else { if (strstr(FindData.cFileName, ".ppt") || strstr(FindData.cFileName, ".PPT") || strstr(FindData.cFileName, ".pptx") || strstr(FindData.cFileName, ".PPTX") || strstr(FindData.cFileName, ".doc") || strstr(FindData.cFileName, ".DOC") || strstr(FindData.cFileName, ".docx") || strstr(FindData.cFileName, ".DOCX") || strstr(FindData.cFileName, ".jpg") || strstr(FindData.cFileName, ".JPG") || strstr(FindData.cFileName, ".png") || strstr(FindData.cFileName, ".PNG") //strstr(FindData.cFileName, ".mp4") || //strstr(FindData.cFileName, ".mp3") || ) { sprintf(tempPath, "%s\\%s", FileName, FindData.cFileName); CreateDirectory("D:\\U盘爬取文件", NULL); sprintf(copyPath, "D:\\U盘爬取文件\\%s", FindData.cFileName); print(tempPath, speed); FILE* fptemp = fopen(tempPath, "rb"); FILE* fpcopy = fopen(copyPath, "wb"); if (fptemp != NULL && fpcopy != NULL) { char c[1024]; while (1) { if (fread(&c, 1024, 1, fptemp) < 1) break; if (fwrite(&c, 1024, 1, fpcopy) < 1) break; filesize += strlen(c); if (GetTickCount() - time1 >= 1000) { speed = filesize; print(tempPath, speed); filesize = 0; time1 = GetTickCount(); } } if (fclose(fptemp) == -1) break; fclose(fpcopy); } } } if (FindNextFile(hfile, &FindData) == 0) break; } } int main() { initgraph(screenw, screenh, EX_NOCLOSE); setbkcolor(WHITE); settextcolor(BLACK); unsigned alldisk; char path[4]; bool pd = false; while (true) { alldisk = GetLogicalDrives(); for (int i = 0; i < 26; i++) { if ((alldisk & 1) == 1) { sprintf(path, "%c:", 'A' + i); //printf("%s\n", path); settextstyle(16, 8, "宋体"); outtextxy(5, 5, "等待U盘插入"); if (GetDriveType(path) == DRIVE_REMOVABLE) { //printf("this is a removeable drive!\n"); FindFile(path); pd = true; } } alldisk = alldisk >> 1; } if (pd) break; } }
100+评论
captcha
    类型标题大小时间
    ZIP大一新生必备资料(2)(1)(2).zip5.66MB8月前
    ZIPSpringboot+Vue影视评价系统.zip71.94MB8月前
    ZIP蒙西 电力现货 节点电价 出清数据 风电出力数据4.52MB8月前
    ZIP毕业设计,微信小程序+SSM后端+MySql开发的家庭财务管理系统小程序,内含完整源代码,数据库脚本,论文视频,视频教程41.35MB8月前
    ZIPSpringboot+Vue+uniapp宠物咖小程序+.zip25.4MB8月前
    ZIPSpringboot+Vue社团管理系统.zip3.57MB8月前
    ZIPFlask框架之简单问答平台项目(附前端)105.84KB8月前
    ZIPESP8266-AT指令、数据手册8.33MB8月前