'--与文件及文件夹操作相关的函数
'--必须引用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文件操作自定义函数合集之一的更多相关文章

  1. php中文件操作常用函数有哪些

    php中文件操作常用函数有哪些 一.总结 一句话总结:读写文件函数 判断文件或者目录是否存在函数 创建目录函数 file_exists() mkdir() file_get_content() fil ...

  2. python 文件操作: 文件操作的函数, 模式及常用操作.

    1.文件操作的函数: open("文件名(路径)", mode = '模式', encoding = "字符集") 2.模式: r , w , a , r+ , ...

  3. python 文件操作的函数

    1. 文件操作的函数 open(文件名(路径), mode="?", encoding="字符集") 2. 模式: r, w, a, r+, w+, a+, r ...

  4. PHP文件操作功能函数大全

    PHP文件操作功能函数大全 <?php /* 转换字节大小 */ function transByte($size){ $arr=array("B","KB&quo ...

  5. MySQL学习——操作自定义函数

    MySQL学习——操作自定义函数 摘要:本文主要学习了使用DDL语句操作自定义函数的方法. 了解自定义函数 是什么 自定义函数是一种与存储过程十分相似的过程式数据库对象.它与存储过程一样,都是由SQL ...

  6. Python基础-week03 集合 , 文件操作 和 函数详解

    一.集合及其运算 1.集合的概念 集合是一个无序的,不重复的数据组合,它的主要作用如下 *去重,把一个列表变成集合,就自动去重了 *关系测试,测试两组数据之前的交集.并集.差集.子集.父级.对称差集, ...

  7. ioctl、文件操作接口函数以及nand的升级模式的操作过程详解

    概述 内核中驱动文件的操作通常是通过write和read函数进行的,但是很多时候再用户空间进行的操作或许不是内核中公共代码部分提供的功能,此时就需要使用一种个性化的方法进行操作--ioctl系统调用. ...

  8. Day3 Python基础学习——文件操作、函数

    一.文件操作 1.对文件操作流程 打开文件,得到文件句柄并赋值给一个变量 通过文件句柄对文件进行操作 关闭文件 #打开文件,读写文件,关闭文件 http://www.cnblogs.com/linha ...

  9. NO.3:自学python之路------集合、文件操作、函数

    引言 本来计划每周完成一篇Python的自学博客,由于上一篇到这一篇遇到了过年.开学等杂事,导致托更到现在.现在又是一个新的学期,春天也越来越近了(冷到感冒).好了,闲话就说这么多.开始本周的自学Py ...

随机推荐

  1. Ubuntu 14.02 cmake升级 失败解决

    错误的提示: CMake Error: Could not find CMAKE_ROOT !!! CMake has most likely not been installed correctly ...

  2. 201521123010 《Java程序设计》第3周学习总结

    1. 本周学习总结 2. 书面作业 1.代码阅读 public class Test1 { private int i = 1;//这行不能修改 private static int j = 2; p ...

  3. 201521123059 《Java程序设计》第十四周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多数据库相关内容. 1.关系型数据库 --建立表格时表中一列中的数据类型必须一致.关系表中的行必须是唯一的,列是不可分的,某些行的某 ...

  4. Sublime自定义语法

    以thinkphp框架的assign函数为例 在sublime\Data\Packages\PHP下 新建文件:assign.sublime-snippet 内容为 <snippet> & ...

  5. HashMap、HashTable、ArrayList、LinkedList、Vector区别

    HashTable和HashMap区别 ①继承不同. public class Hashtable extends Dictionary implements Map public class Has ...

  6. Oracle存储过程经典入门

    ok基本就这些介绍

  7. 函数原型属性-JavaScript深入浅出(三)

    前两次总结了JavaScript中的基本数据类型(值类型<引用类型>,引用类型<复杂值>)以及他们在内存中的存储,对内存空间有了一个简单的了解,以及第二次总结了this深入浅出 ...

  8. Django中的信号及其用法

    Django中提供了"信号调度",用于在框架执行操作时解耦. 一些动作发生的时候,系统会根据信号定义的函数执行相应的操作 Django中内置的signal Model_signal ...

  9. MVC查询数据接收及校验

    本来想写一篇aspx的TreeView控件绑值的文章的,在写案例的时候,写了一半,发现有些地方还得考虑以下,就留待下次了. 这一篇的话,是最近在开发一个项目的时候,有大量的页面和数据表,需要花式查询, ...

  10. 西邮linux兴趣小组2014纳新免试题(一)

    [第一关] 题目 0101001001100001011100100010000100011010000001110000000011001111100100000111001100000000000 ...