c++实现磁盘扫描Word文件下载.docx

上传人:b****5 文档编号:21201211 上传时间:2023-01-28 格式:DOCX 页数:18 大小:1.47MB
下载 相关 举报
c++实现磁盘扫描Word文件下载.docx_第1页
第1页 / 共18页
c++实现磁盘扫描Word文件下载.docx_第2页
第2页 / 共18页
c++实现磁盘扫描Word文件下载.docx_第3页
第3页 / 共18页
c++实现磁盘扫描Word文件下载.docx_第4页
第4页 / 共18页
c++实现磁盘扫描Word文件下载.docx_第5页
第5页 / 共18页
点击查看更多>>
下载资源
资源描述

c++实现磁盘扫描Word文件下载.docx

《c++实现磁盘扫描Word文件下载.docx》由会员分享,可在线阅读,更多相关《c++实现磁盘扫描Word文件下载.docx(18页珍藏版)》请在冰豆网上搜索。

c++实现磁盘扫描Word文件下载.docx

DWORD 

count;

//文件个数 

24. 

Transform_count;

//已传送文件个数 

25. 

26. 

CIniReader 

*Reader;

27. 

CIniWriter 

*Writer;

28. 

FILE 

*fp;

//文件指针,创建路径文件 

29.public:

30. 

31.TCHAR 

GetFirstFile();

//得到第一个文件路径 

32.//void 

ModifyPath(TCHAR 

*path);

//修改路径字符串 

33.void 

SearchforAllDriver();

//搜索所有驱动器 

34.void 

GetDriverList();

//得到驱动器列表 

35.bool 

Search(TCHAR 

*Path,TCHAR 

*File);

//递归搜索 

36.bool 

TcharMarch(TCHAR 

*fileName,TCHAR 

*Extension);

//文件后缀名匹配 

37.void 

SetExpansion(TCHAR 

*Expansion);

//设置新的文件后缀 

38.void 

SetConfigName(TCHAR 

*ConfigName);

//设置需要操作的配置文件名 

39.void 

InitOperateIni(TCHAR 

//初始化配置信息类 

40.void 

GetAllExpansion();

//得到所有后缀名并且检索目录写入文件 

41.};

42. 

43.ScanDisk:

:

*FileName)//初始化工作 

44.{ 

45. 

memset(this->

DriveString,0,sizeof(this->

DriveString));

46. 

Driver,0,sizeof(this->

Driver));

47. 

Expansion,0,sizeof(this->

Expansion));

48. 

FileName,0,sizeof(this->

FileName));

49. 

Name,0,sizeof(this->

Name));

50. 

ConfigName,0,sizeof(this->

ConfigName));

51. 

this->

count=0;

52. 

Transform_count=0;

//已传送文件个数为0 

53. 

54. 

memcpy(this->

Expansion,Expansion,wcslen(Expansion)*2);

55. 

FileName,FileName,wcslen(FileName)*2);

56. 

//MessageBox(NULL,this->

FileName,NULL,MB_OK);

57.// 

MessageBox(NULL,this->

Expansion,NULL,MB_OK);

58. 

59.} 

60. 

61.ScanDisk:

~ScanDisk() 

62.{ 

63. 

fclose(this->

fp);

64. 

65.} 

66. 

67.void 

ScanDisk:

*Expansion) 

68.{ 

69. 

70. 

71.} 

72. 

73.void 

*ConfigName) 

74.{ 

75. 

76. 

ConfigName,ConfigName,wcslen(ConfigName)*2);

77.} 

78. 

79.void 

80.{ 

81. 

82. 

83. 

Writer=new 

CIniWriter(this->

ConfigName);

84. 

Reader=new 

CIniReader(this->

85. 

(this->

Writer)->

WriteInteger(L"

Setting"

L"

count"

this->

count);

86. 

Transform_count"

Transform_count);

87.} 

88. 

89.void 

GetAllExpansion()//读取配置文件中的每一个后缀名,遍历磁盘写入文件 

90.{ 

91. 

*expansion=(this->

Reader)->

ReadString(L"

 

L"

extension"

);

//此处设计不是很好 

92. 

int 

length=lstrlen(expansion)+1;

//没有斜杠零 

93. 

i=0;

94. 

temp[MAX_PATH]={0};

95. 

for 

(int 

j=0;

j<

length;

j++) 

96. 

97. 

98. 

if 

(((*expansion)!

=L'

'

)&

&

((*expansion)!

\0'

)) 

99. 

100. 

memcpy(&

temp[i],expansion,sizeof(TCHAR));

101. 

temp[i++];

102. 

expansion++;

103. 

104. 

105. 

(((*expansion)==L'

)||((*expansion)==L'

106. 

107. 

108. 

temp[i]=L'

;

109. 

SetExpansion(temp);

110. 

111. 

((*expansion)==L'

) 

112. 

113. 

break;

114. 

115. 

116. 

117. 

memset(temp,0,sizeof(temp));

118. 

119. 

120. 

121. 

122. 

123. 

124. 

125. 

126.} 

127. 

128. 

129.TCHAR 

GetFirstFile() 

130.{ 

131. 

number=(this->

ReadInteger(L"

//看看读到第几个文件了 

132. 

fp=_wfopen(this->

FileName,L"

r"

//读的方式打开 

133. 

if(!

fp) 

134. 

135. 

cout<

Can 

not 

open 

the 

.txt 

file"

endl;

136. 

137. 

else 

138. 

139. 

file 

is 

opened 

!

140. 

141. 

//TCHAR 

path[MAX_PATH]={0};

142. 

i<

=number;

i++) 

143. 

144. 

fgetws(this->

Name,MAX_PATH,this->

145. 

146. 

//fgetws(this->

147. 

Name[lstrlen(this->

Name)-1]=0;

//去掉文件最后的0A 

148. 

wprintf(this->

Name);

149. 

Name,NULL,MB_OK);

150. 

Transform_count++;

151. 

152. 

153. 

154. 

return 

Name;

155. 

156.} 

157. 

158.void 

SearchforAllDriver() 

159.{ 

160. 

161. 

162. 

163. 

164. 

driverCount=0;

165. 

pDrive= 

DriveString;

166. 

while( 

*pDrive 

167. 

168. 

pDrive 

+= 

wcslen( 

1;

169. 

driverCount++;

170. 

171. 

172.// 

printf("

%d\n"

driverCount);

//总共几个驱动器 

173. 

174. 

175. 

a+"

//追加的方式打开 

176. 

177. 

178. 

179. 

180. 

181. 

182. 

183. 

184. 

//for 

driverCount;

185. 

//{ 

186. 

187. 

188. 

Driver,pDrive,wcslen(this->

DriveString)+1);

//控制字符长度,和缓冲区 

189. 

Driver,NULL,MB_OK);

190. 

Search(this->

Driver,this->

Expansion);

191. 

fflush(this->

192. 

pDrive=pDrive+wcslen(pDrive)+1;

193. 

194. 

//} 

195. 

196. 

197.} 

198. 

199.void 

GetDriverList() 

200.{ 

201. 

202. 

前一个字节为令牌,后面的52字节为驱动器跟相关属性 

203. 

GetLogicalDriveStrings(sizeof(DriveString), 

DriveString);

204. 

DriveString,DriveString,sizeof(this->

205.} 

206. 

207. 

208.bool 

*Extension)//文件后缀名匹配 

209.{ 

210. 

length_of_ext=wcslen(Extension);

211. 

length_of_name=wcslen(fileName);

212. 

213. 

while(i<

length_of_ext) 

214. 

215. 

(fileName[i+(length_of_name-length_of_ext)]!

=Extension[i]) 

216. 

217. 

false;

218. 

219. 

220. 

i++;

221. 

222. 

true;

223. 

224.} 

225. 

226.bool 

*File) 

227.{ 

228. 

HANDLE 

hFind;

229. 

WIN32_FIND_DATA 

wfd;

230. 

231. 

ZeroMemory(&

wfd,sizeof(WIN32_FIND_DATA));

232. 

PathTemp[MAX_PATH];

233. 

memset(PathTemp,0,sizeof(PathTemp));

234. 

235. 

swprintf(PathTemp,L"

%s\\*.*"

Path);

236. 

hFind=FindFirstFile(PathTemp,&

wfd);

237. 

238. 

if(INVALID_HANDLE_VALUE==hFind) 

239. 

240. 

//MessageBox(NULL,L"

INVALID_HANDLE_VALUE"

FindFirstFile"

MB_OK);

241. 

242. 

243. 

244. 

do 

245. 

246. 

if('

.'

==wfd.cFileName[0]) 

247. 

248. 

continue;

249. 

250. 

251. 

if(wfd.dwFileAttributes 

FILE_ATTRIBUTE_DIRECTORY) 

252. 

253. 

%s\\%s"

Path,wfd.cFileName);

254. 

//MessageBox(NULL,PathTemp,"

Directory"

255. 

//wprintf(PathTemp);

256. 

//printf("

\n"

257. 

Search(PathTemp,File);

258. 

259. 

260. 

261. 

262. 

263. 

(TcharMarch(wfd.cFileName,File)) 

264. 

265. 

266. 

267. 

Found"

PathTemp,MB_OK);

268. 

//printf(PathTemp);

269. 

270. 

271./////////////////////////////////////////////////////////////////////////////////// 

272.// 

temp[MAX_PATH];

273.// 

memcpy(temp,"

sizeof(temp));

274.// 

temp[MAX_PATH-2]=L'

275.// 

memcpy(temp,PathTemp,lstrlen(PathTemp)*2);

276.////////////////////////////////////////////////////////////////////////////////// 

277. 

fwprintf(this->

fp,L"

%s"

PathTemp);

278. 

279. 

280. 

count++;

//文件个数加1 

281. 

282. 

283. 

284. 

285. 

}while(FindNextFile(hFind,&

wfd));

286. 

287. 

FindClose(hFind);

288. 

289. 

290. 

291.} 

这个代码必须在unicode工程下使用,支

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 表格模板 > 表格类模板

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1