VB中FSO对象用法详解_第1页
VB中FSO对象用法详解_第2页
VB中FSO对象用法详解_第3页
VB中FSO对象用法详解_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、要应用fso 对象,须要引用一个名为scripting 的类型库,方法是,执行vb6.0 的菜单项“ 工程 /引用 ” ,添加引用列表框中的“microsoft scripting runtime”一项。然后我们在“ 对象浏览器 ” 中就可以看到scripting 类型库下的众多对象及其方法、属性。1、判断光驱的盘符:function getcdrom() 返回光驱的盘符(字母 ) dim fso as new filesystemobject 创建fso 对象的一个实例dim fsodrive as drive, fsodrives as drives 定义驱动器、驱动器集合对象set fs

2、odrives = fso.drives for each fsodrive in fsodrives 遍历所有可用的驱动器if fsodrive.drivetype = cdrom then 如果驱动器的类型为cdrom getcdrom = fsodrive.driveletter 输出其盘符else getcdrom = end if next set fso = nothing set fsodrive = nothing set fsodrives = nothing end function 2、判断文件、文件夹是否存在: 返回布尔值 :true 存在, false 不存在, fi

3、lername 文件名function fileexist(filename as string) dim fso as new filesystemobject if fso.fileexists(filename) = true then fileexist = true else fileexist = false end if set fso = nothing end function 返回布尔值 :true 存在, false 不存在, foldername 文件夹function folderexist(foldername as string) dim fso as new f

4、ilesystemobject if fso.folderexists(foldername) = true then folderexist = true else folderexist = false end if set fso = nothing end function 3、获取驱动器参数: 返回磁盘总空间大小(单位: m), drive = 盘符a ,c, d . function allspace(drive as string) dim fso as new filesystemobject, drv as drive set drv = fso.getdrive(drive

5、) 得到 drv 对象的实例if drv.isready then 如果该驱动器存在(软驱或光驱里有盘片,硬盘存取正常) allspace = format(drv.totalsize / (2 20), 0.00) 将字节转换为兆else allspace = 0 end if set fso = nothing set drv = nothing end function 返回磁盘可用空间大小(单位: m),drive = 盘符a ,c, d . function freespace(drive) dim fso as new filesystemobject, drv as drive

6、set drv = fso.getdrive(drive) if drv.isready then freespace = format(drv.freespace / (2 20), 0.00) end if set fso = nothing set drv = nothing end function 获取驱动器文件系统类型,drive = 盘符a ,c, d . function fstype(drive as string) dim fso as new filesystemobject, drv as drive set drv = fso.getdrive(drive) if d

7、rv.isready then fstype = drv.filesystem else fstype = end if set fso = nothing set drv = nothing end function 4,获取系统文件夹路径: 返回 windows 文件夹路径function getwindir() dim fso as new filesystemobject getwindir = fso.getspecialfolder(windowsfolder) set fso = nothing end function 返回 windowssystem 文件夹路径functio

8、n getwinsysdir() dim fso as new filesystemobject getwinsysdir = fso.getspecialfolder(systemfolder) set fso = nothing end function 5,综合运用:一个文件备份通用过程: filename = 文件名, drive = 驱动器, folder = 文件夹 (一层 ) sub backupfile(filename as string, drive as string, folder as string)dim fso as new filesystemobject 创建

9、fso 对象实例dim dest_path as string, counter as long counter = 0 do while counter 6 如果驱动器没准备好,继续检测。共检测6 秒counter = counter 1 call waitfor(1) 间隔1 秒if fso.drives(drive).isready = true then exit do end if loop if fso.drives(drive).isready = false then 6 秒后目标盘仍未准备就绪,退出msgbox 目标驱动器 & drive & 没有准备好!,

10、vbcritical exit sub end if if fso.getdrive(drive).freespace fso.getfile(filename).size then msgbox 目标驱动器空间太小!, vbcritical 目标驱动器空间不够,退出exit sub end if if right(drive, 1) : then drive = drive & : end if if left(folder , 1) then folder = & folder end if if right(folder , 1) then folder = folder & end if dest_path = drive & folder if not fso.folderexists(dest_path) then 如果目标文件夹不存在,创建之fso.createfolder dest_path end if fso.copyfile filename, dest_path & fso.getfilename(filename), true 拷贝,直接覆盖同名文件msgbox 文件备份完毕。, vbokonly s

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论