VB6文件操作自定义函数合集之一
'--与文件及文件夹操作相关的函数
'--必须引用FSO的ACTIVE OBJECT
Dim strList As String '--列表串,返回文件列表
'================
'--文件操作区
Public Function CopyFile(SourseStr As String, WhereStr As String, Optional WhereStr2 As String = "") As Boolean
On Error Resume Next
Dim myFso As New FileSystemObject
Dim myFile As File
If myFso.FileExists(SourseStr) Then
Set myFile = myFso.GetFile(SourseStr)
myFile.Copy (WhereStr)
If WhereStr2 <> "" Then
myFile.Copy (WhereStr2)
End If
CopyFile = True
Set myFile = Nothing
Else
CopyFile = False
End If
End Function
Public Function DeleteFileX(ByVal strFileAndPath As String) As Boolean
On Error GoTo deleteError
DeleteFileX = False
Dim myFso As New FileSystemObject
Dim myFile As File
If myFso.FileExists(strFileAndPath) = True Then
Set myFile = myFso.GetFile(strFileAndPath)
myFile.Attributes = Normal
myFso.DeleteFile strFileAndPath, True
DeleteFileX = True
Set myFile = Nothing
End If
Exit Function
deleteError:
DeleteFileX = False
Err.Clear
End Function
'--检查文件是否存在
Public Function IsFileExits(ByVal strFile As String) As Boolean
On Error GoTo IsFileExitsErr
IsFileExits = True
Dim myFso As New FileSystemObject
If Dir(strFile) = "" And myFso.FileExists(strFile) = False Then
IsFileExits = False
End If
Set myFso = Nothing
Exit Function
IsFileExitsErr:
Err.Clear
IsFileExits = False
End Function
'====================================
'--文件夹操作区
'--复制文件夹
'--若要复制C盘下的window文件夹到“d:\dd"文件夹的下面,必须使用
'--copydir "c:\window\","d:\dd\"表示
Public Function CopyDir(SourseStr As String, WhereStr As String, Optional WhereStr2 As String = "") As Boolean
On Error GoTo CopyDirErr
Dim myFso As New FileSystemObject
Dim myFolder As Folder
If myFso.FolderExists(SourseStr) Then
Set myFolder = myFso.GetFolder(SourseStr)
myFolder.Copy (WhereStr)
If WhereStr2 <> "" Then
myFolder.Copy (WhereStr2)
End If
CopyDir = True
Set myFolder = Nothing
Else
CopyDir = False
End If
'------
Exit Function
CopyDirErr:
CopyDir = False
Err.Clear
End Function
'--删除文件 夹
Public Function DeleteDirX(strFileAndPath As String) As Boolean
On Error GoTo deleteError
DeleteDirX = False
'-----
Dim myFso As New FileSystemObject
Dim myFolder As Folder
If myFso.FolderExists(strFileAndPath) = True Then
Set myFolder = myFso.GetFolder(strFileAndPath)
myFolder.Attributes = Normal
myFso.DeleteFolder strFileAndPath
DeleteDirX = True
End If
Set myFolder = Nothing
Set myFso = Nothing
Exit Function
deleteError:
DeleteDirX = False
End Function
'------
Public Function IsFolderExist(ByVal strFolder As String) As Boolean
On Error GoTo IsFolderExistERR
IsFolderExist = False
'-------------------------
Dim myFso As New FileSystemObject
If myFso.FolderExists(strFolder) = True Then
IsFolderExist = True
End If
Set myFso = Nothing
'------------------------------------
Exit Function
IsFolderExistERR:
Err.Clear
End Function '--创建新文件夹-在本地创建
Public Function CreateDir(strLongDir As String) As Boolean
Dim strDir$, i As Integer
Dim strdirX$
Dim strN$
On Error GoTo yy
Dim myFso As New FileSystemObject
If Right(strLongDir, ) <> "\" And Right(strLongDir, ) <> "/" Then
strDir = strLongDir & "\"
Else
strDir = strLongDir
End If
For i = To Len(strDir)
strN = Mid(strDir, i, )
If strN = "\" Or strN = "/" Then
If i = Then GoTo xx
strdirX = Left(strDir, i - )
If myFso.FolderExists(strdirX) = False Then
MkDir strdirX
End If
End If
xx:
Next
CreateDir = True
Exit Function
yy:
CreateDir = False
End Function
'--得到某个Folder下所有的文件列表
Public Function ShowFolderList(ByVal folderSpec As String) As String
On Error GoTo ShowFolderListErr
ShowFolderList = ""
'------------------------------
Dim fS As New FileSystemObject, F As Folder, F1 As File, fC As Files, s As String
Set F = fS.GetFolder(folderSpec)
Set fC = F.Files
s = ""
For Each F1 In fC
If s = "" Then
s = F1.Name
Else
s = s & "|" & F1.Name
End If
Next
ShowFolderList = s
'-------------
Exit Function
ShowFolderListErr:
Err.Clear
End Function
'----得到某个FOLDER下所有的夹
Public Function ShowFolderFolderList(ByVal folderSpec As String) As String
On Error GoTo ShowFolderFolderListERR
ShowFolderFolderList = ""
'-----------------------
Dim fS As New FileSystemObject, F As Folder, F1 As Folder, fC As Folders, s As String
Set F = fS.GetFolder(folderSpec)
Set fC = F.SubFolders
s = ""
For Each F1 In fC
If s = "" Then
s = F1.Name
Else
s = s & "|" & F1.Name
End If
Next
ShowFolderFolderList = s
'--------------------------
Exit Function
ShowFolderFolderListERR:
Err.Clear
End Function
VB6文件操作自定义函数合集之一的更多相关文章
- php中文件操作常用函数有哪些
php中文件操作常用函数有哪些 一.总结 一句话总结:读写文件函数 判断文件或者目录是否存在函数 创建目录函数 file_exists() mkdir() file_get_content() fil ...
- python 文件操作: 文件操作的函数, 模式及常用操作.
1.文件操作的函数: open("文件名(路径)", mode = '模式', encoding = "字符集") 2.模式: r , w , a , r+ , ...
- python 文件操作的函数
1. 文件操作的函数 open(文件名(路径), mode="?", encoding="字符集") 2. 模式: r, w, a, r+, w+, a+, r ...
- PHP文件操作功能函数大全
PHP文件操作功能函数大全 <?php /* 转换字节大小 */ function transByte($size){ $arr=array("B","KB&quo ...
- MySQL学习——操作自定义函数
MySQL学习——操作自定义函数 摘要:本文主要学习了使用DDL语句操作自定义函数的方法. 了解自定义函数 是什么 自定义函数是一种与存储过程十分相似的过程式数据库对象.它与存储过程一样,都是由SQL ...
- Python基础-week03 集合 , 文件操作 和 函数详解
一.集合及其运算 1.集合的概念 集合是一个无序的,不重复的数据组合,它的主要作用如下 *去重,把一个列表变成集合,就自动去重了 *关系测试,测试两组数据之前的交集.并集.差集.子集.父级.对称差集, ...
- ioctl、文件操作接口函数以及nand的升级模式的操作过程详解
概述 内核中驱动文件的操作通常是通过write和read函数进行的,但是很多时候再用户空间进行的操作或许不是内核中公共代码部分提供的功能,此时就需要使用一种个性化的方法进行操作--ioctl系统调用. ...
- Day3 Python基础学习——文件操作、函数
一.文件操作 1.对文件操作流程 打开文件,得到文件句柄并赋值给一个变量 通过文件句柄对文件进行操作 关闭文件 #打开文件,读写文件,关闭文件 http://www.cnblogs.com/linha ...
- NO.3:自学python之路------集合、文件操作、函数
引言 本来计划每周完成一篇Python的自学博客,由于上一篇到这一篇遇到了过年.开学等杂事,导致托更到现在.现在又是一个新的学期,春天也越来越近了(冷到感冒).好了,闲话就说这么多.开始本周的自学Py ...
随机推荐
- HTML的基本标签及语法
一.HTML基本标签head部分 HTML文档的基本结构 <!DOCTYPE html> <html> <head> <meta charset=" ...
- IT之光
作为一个IT界的新新人才,现在拥有第一个博客,可以在这里学习和分享IT方面的知识和技术.
- 作业2——需求分析&原型设计
需求分析: 软件的最终目的是用来解决用户的某些问题,需求分析就是要理解要解决的问题,真正明确用户需求.下面是我们初步的需求分析: 1.访问软件项目的真实用户(至少10个),确保软件真正体现用户的需求, ...
- 201521123026 《Java程序设计》第5周学习总结
1. 本章学习总结 尝试使用思维导图总结有关多态与接口的知识点 使用常规方法总结其他上课内容 1.接口的出现时为了实现多态,多态的实现不一定依赖于接口. 2.接口的常见成员有:全局常量和抽象方法. 3 ...
- 201521123071 《JAVA程序设计》第十四周学习总结
第14周作业-数据库 1. 本周学习总结 1.1 以你喜欢的方式(思维导图.Onenote或其他)归纳总结多数据库相关内容. 1.使用JDBC将Java程序与数据库连接 1.1注册驱动 Class.f ...
- 201521123079《java程序设计》第9周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常相关内容. 2. 书面作业 本次PTA作业题集异常 1.常用异常 题目5-1 1.1 截图你的提交结果(出现学号) 1.2 自己 ...
- virtualbox修改主机名
virtualbox修改主机名 /etc/hostname /etc/hosts
- TCP/IP(三)数据链路层~2
一.局域网 1.1.局域网和以太网的区别和联系 局域网:前面已经介绍了,其实就是学校里面.各个大的公司里,自己组件的一个小型网络,这种就属于局域网. 以太网:以太网(Ethernet)指的是由Xero ...
- Android Studio 字体和字号调整
点击File,Settings. 找到Editor-Colors&Fonts-Font 点击Save As... 改个名字点击OK. 1为字体,2为字号,3为行间距. 我认为字体设置为Cons ...
- Nexus 私有仓库搭建与 Maven 集成
Nexus 私有仓库搭建与 Maven 集成 |作者:RexFang |出处:http://www.cnblogs.com/rexfang/ |关于作者:Java 程序员一枚 |版权:本文版权归作者和 ...