|
||||
拷贝前的空间测试 冷含生 兰州铁道学院 (73007冷含生 |
|
在拷贝多个文件时,经常会遇到因盘(指硬盘和软盘)的空间不够而终止 的情况。即使用Pctools拷贝,也存在以下三个缺点: 一、即使先查某一目录下所要拷贝的文件占空间的总和,再查看目标盘所 剩空间,虽然前者大于后者,但仍存在拷贝过程中因盘空间不够而终止的情况 ; 二、不能直接查看多个目录下多个文件所占空间的总和; 三、操作繁琐。 为了解决上述问题,笔者用Turbo C写了一个小程序,在拷盘前运 行该程序,可以判定目标盘所剩空间是否能拷下所要拷贝的多个文件。 基本思想 先通过getdfree()函数,得到目标驱动器中每簇所占的字节数 ,再将每个文件的长度转化成所需目标盘的簇数,进而计算文件的长度,进行 累加,最后判断目标盘所剩空间是否大于所要拷贝的所有文件所需空间,即可 得出结论。为了使用户知道缺少多少空间,该程序还将所需空间和目标盘的自 由空间显示出来。 使用方法 把该程序编辑、编译,得到exe文件,假设为testdisk exe,则使用格式如下: testdisk pathfile[+pathfile+……] drive 其中pathfile为某一文件或某几个文件或某些子目录中的文件, 支持通配符“*”与“?”;drive为目标盘所在驱动器。 该程序在TW286上运行通过。 源程序清单如下: ***** #include "conio.h" #include "dir.h" #include "dos.h" #include "stdio.h" #include "stdlib.h" #include "string.h" main(int argc,char*argv[]) { struct ffblk dta; struct dfree disk; char pathname[30]; void far *sys; int i,j,base,drive,right; long int freedisk,all-file-long=0,temp; if(argc!=3) { printf("\nNO PARAMETERS OR TOO MANY"); printf("\n\nCOMMAND:"); printf("\n look source-subname[+subname] drive"); printf("\nEXAMPLES:"); printf("\nlook c:\mysub\*.*+c:tools\*.exe a:\n"); return 0; } switch(argv[2][0]) { case'a': case'A': drive=1; break; case'b': case'B': drive=2; break; case'c': case'C': drive=3; break; case'd': case'D': drive=4; break; default: printf ("nPARAMETERS ERROR"); return 0; } getdfree(drive,&disk); base=disk.df-bsec*disk.df-sclus; freedisk=disk.df-avail; freedisk=freedisk*base; i=0; while(i for(j=0;(argv[1][i]&&(argv[1][i]!='+'));i++,j++) pathname[j]=argv[1][i]; i++; pathname[j]='\0'; right=findfirst(pathname,&dta,0*16); while(!right) { if(dta.ff-fsize%base) { temp=dta.ff-fsize; all-file-long=all-file-long+(temp/base+1)*base; } else { temp=dta.ff-fsize; all-file-long=all-file-long+temp; } right=findnext(&dta); } } printf("n\nNEED TOTAL SPACE:"); printf("%12ld Bytes",all-file-long); printf("\nTHE DISK LEFT SPACE:"); printf("%12ld Bytes",freedisk); if(all-file-long<=freedisk) printf("\n\n******The space is enough *****"); else printf("\n\n*****No such space to copy these files*****"); return 0; ***** (计算机世界报 1994年 第9期) |
周报全文频道联系方式:010-68130909 |
||||||
| 【关于我们】 【广告服务】 【周报发行】 【投稿指南】 【投稿声明】 【联系方式】 【法律声明】 【媒体手册】 【编读往来】 |
||||||
| Copyright© ccw.com.cn,All rights reserved | ||||||
| 中国计算机世界出版服务公司版权所有 | ||||||