代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
C
】
纯API实现多个文件分割再合并
作者:
Owen
/ 发布于
2014/10/10
/
961
#include <windows.h> #include <stdio.h> #include <string.h> #include <commdlg.h> int main(int argc, char* argv[]) { OPENFILENAME File; static char filepath[MAX_PATH]; LPTSTR filename=filepath; ZeroMemory(&File,sizeof(File)); File.lStructSize=sizeof(File); File.Flags=OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_ALLOWMULTISELECT; File.hwndOwner=NULL; File.lpstrFilter="All Files (*.*)\\0*.*\\0"; File.nFilterIndex=1; File.lpstrFile=filepath; File.nMaxFile=sizeof(filepath); if(GetOpenFileName(&File)) { LPTSTR SavePath="D:"; HANDLE rf=CreateFile(filename,GENERIC_READ,FILE_SHARE_READ,0,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,0); if(rf!=INVALID_HANDLE_VALUE) { DWORD FileLength=GetFileSize(rf,NULL); DWORD PartLength=FileLength/3+FileLength%3; int nCount=(FileLength+(FileLength%PartLength==0?0:PartLength-FileLength%PartLength))/PartLength; char* pBuf=new char[PartLength]; int len=strlen(filename); for(int c=len;c>0;c--) if(filename[c]=='\\\\') break; filename+=c+1; for(int i=1;i<=nCount;i++) { char temppath[MAX_PATH]; char tempnum[2]; DWORD ByteCount=(i<nCount?ByteCount+PartLength:FileLength-PartLength); ReadFile(rf,pBuf,PartLength,&ByteCount,0); strcpy(temppath,SavePath); strcat(temppath,"\\\\"); strcat(temppath,filename); wsprintf(tempnum,"%d",i); strcat(temppath,tempnum); HANDLE wf=CreateFile(temppath,GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0); DWORD BackBytes=i<nCount?PartLength:FileLength-ByteCount; WriteFile(wf,pBuf,ByteCount,&BackBytes,0); FlushFileBuffers(wf); CloseHandle(wf); } CloseHandle(rf); delete pBuf; } LPTSTR savepath=SavePath; char tempfilepath[MAX_PATH]; strcpy(tempfilepath,SavePath); strcat(tempfilepath,"\\\\"); strcat(tempfilepath,filename); strcpy(filename,tempfilepath); HANDLE writefile=CreateFile(filename,GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0); if(writefile!=INVALID_HANDLE_VALUE) { int filecount=1; char numchar[2]; char temppath[MAX_PATH]={0}; strcpy(temppath,filename); wsprintf(numchar,"%d",filecount++); strcat(temppath,numchar); while(GetFileAttributes(temppath)!=-1) { HANDLE readfile=CreateFile(temppath,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0); DWORD FileLength=GetFileSize(readfile,NULL); DWORD BuffSize=FileLength<10485760L?FileLength:10485760L; int nCount=(FileLength+(FileLength%BuffSize==0?0:BuffSize-FileLength%BuffSize))/BuffSize; char* pBuf=new char[BuffSize]; for(int i=1;i<=nCount;i++) { DWORD ByteCount=(i<nCount?ByteCount+BuffSize:FileLength-BuffSize); ReadFile(readfile,pBuf,BuffSize,&ByteCount,0); DWORD BackBytes=i<nCount?BuffSize:FileLength-ByteCount; WriteFile(writefile,pBuf,ByteCount,&BackBytes,0); } FlushFileBuffers(writefile); CloseHandle(readfile); delete pBuf; strcpy(temppath,filename); wsprintf(numchar,"%d",filecount++); strcat(temppath,numchar); } CloseHandle(writefile); } } return 0; }
试试其它关键字
文件分割
文件合并
同语言下
.
获取手机通讯录 iOS去除数字以外的所有字符
.
异步加载音乐等资源
.
交通罚单管理系统
.
freemark实现,简单的替换
.
计算斐波那契数列
.
base64解码 包括解码长度
.
图像显示
.
冒泡排序
.
输入十进制数,输出指定进制
.
链式栈
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
Owen
贡献的其它代码
(
5
)
.
用户、责任及 HR
.
最小生成树(prim+mapped_heap邻接表形式)
.
获取cpu使用率,获取某一进程cpu使用率
.
后台关闭当前页面并传值
.
纯API实现多个文件分割再合并
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3