转载 FileSystemObject的方法和属性 js filesystemobject

原文地址:FileSystemObject的方法和属性作者:衹因为你

FileSystemObject的方法和属性

1,FileExists : 如果文件存在就返回TRUE
Sub FileExists()
Dim fs As Object
Dim strFile As String
Set fs = CreateObject("scripting.filesystemobject")
strFile = InputBox("Enter the full name of the file:")
If fs.FileExists(strFile) Then
MsgBoxstrFile & " was found."
Else
[转载]FileSystemObject的方法和属性 js filesystemobject
MsgBox "Filedoes not exist."
End If
End Sub

2,GetFile :返回一对象File

3,GetFileName :返回带路径文件名

4,GetFileVersion : 返回文件版本

5,CopyFile : 复制文件
Sub CopyFile()
Dim fs As Object
Dim strFile As String
Dim strNewFile As String
strFile = "c:hello.doc"
strNewFile = "C:programs fileshello.doc"
Set fs = CreateObject("Scripting.filesystemobject")
fs.CopyFile strFile, strNewFile
MsgBox "A copy of the specified file was created."
Set fs = Nothing
End Sub

6,MoveFile :移动文件

7,DeleteFile : 删除文件
Sub DeleteFile()
Dim fs As FileSystemObject
Set fs = New FileSystemObject
fs.DeleteFile "C:programs fileshello.doc"
MsgBox "The requested file was deleted."
End Sub

8,DriveExists : 如果给定硬盘存在则返回TRUE
Function DriveExists(disk)
Dim fs As Object
Dim strMsg As String
Set fs = CreateObject("scripting.filesystemobject")
If fs.DriveExists(disk) Then
strMsg ="drive [" & UCase(disk) & "]exists."
Else
strMsg ="drive [" & UCase(disk) & "] wasnot found."
End If
DriveExists = strMsg
'run this function from the worksheet
'by enter in any cell the following: =driveexists("e:")
End Function

9,GetFolder : 返回对象Folder
Sub FilesInFolder()
Dim fs As Object
Dim objFolder As Object
Dim objFile As Object
Dim i As Integer
i = 1
Set fs = CreateObject("scripting.filesystemobject")
Set objFolder = fs.GetFolder("C:")

Range("A1").Select
With Selection
For EachobjFile In objFolder.Files
.Offset(i, 0).Value = objFile.Name
.Offset(i, 1).Value = objFile.Type
i = i + 1
NextobjFile
End With
End Sub

10,GetSpecialFolder : 返回操作系统文件夹路径
0-视窗文件夹
1-系统文件夹
2-临时文件夹

SubSpecialFolders()
Dim fs As Object
Dim strWindowsFolder As String
Dim strSystemFolder As String
Dim strTempFolder As String
Set fs = CreateObject("scripting.filesystemobject")
strWindowsFolder = fs.GetSpecialFolder(0)
strSystemFolder = fs.GetSpecialFolder(1)
strTempFolder = fs.GetSpecialFolder(2)
MsgBox strWindowsFolder & vbCrLf &_
strSystemFolder & vbCrLf & _
strTempFolder, vbInformation + vbOKOnly, _
"special folders"
End Sub

11,CreateFolder : 创建文件夹
Sub MakeNewFolder()
Dim fs, objFolder
Set fs = CreateObject("scripting.filesystemobject")
Set objFolder = fs.CreateFolder("c:testfolder")
MsgBox " A new folder named “" & objFolder.Name& "” was created."
End Sub

12,CopyFolder : 复制文件夹
Sub MakeFolderCopy()
Dim fs As FileSystemObject
Set fs = New FileSystemObject
If fs.FolderExists("c:testfolder") Then
fs.CopyFolder "c:testfolder", "c:finalfolder"
MsgBox "The Folder was copied!"
End If
End Sub

13,MoveFolder :移动文件夹

14,DeleteFolder : 删除文件夹
Sub RemoveFolder()
Dim fs As FileSystemObject
Set fs = New FileSystemObject
If fs.FolderExists("c:testfolder") Then
fs.DeleteFolder "c:testfolder"
MsgBox "TheFolder was deleted."
End If
End Sub

15,CreateTextFile : 创建文本文件

16,OpenTextFile : 打开文本文件
Sub ReadTextFile()
Dim fs As Object
Dim objFile As Object
Dim strContent AsString'定义文件内容
Dim strFileName As String
Dim i As Integer
i = 1
strFileName = "C:Windowswin.ini"
Set fs = CreateObject("scripting.filesystemobject")
Set objFile = fs.OpenTextFile(strFileName)
Do While Not objFile.AtEndOfStream
'******分行列出文件内容******
strContent =objFile.ReadLine
Range("a"& i) = strContent
i = i +1
'******读取全部内容不分行******
' strContent= strContent & objFile.ReadLine &vbCrLf
Loop
objFile.Close
Set objFile = Nothing
End Sub

  

爱华网本文地址 » http://www.aihuau.com/a/25101010/31225.html

更多阅读

电话邀约面试的方法和技巧 电话邀约面试技巧

电话邀约面试的方法和技巧在简历筛选后要进行的一个环节就是电话邀约面试,而越来越多的HR报怨电话邀约时对方的反应很正常,也答应要来面试,但到达率却很低,还有的直接答复说再了解一下公司,之后也再无音信。从某种程度上来说,应聘者对HR

怎么在家赚钱_在家赚钱的方法和技巧 在家赚钱的十种方法

怎么在家赚钱_在家赚钱的方法和技巧——简介很多网友都比较有赚钱的意识,尤其是现在的一些大学生寒假在家除了学习也会选择一些网上赚钱的项目来做一做赚钱补习费也很不错。学会在家赚钱也可以解决一些待业人员的就业问题,本经验分享

牛奶洗脸的方法和好处? 纯牛奶洗脸有什么好处

牛奶洗脸的方法和好处?——简介 用牛奶来美容可以去除脸上的皱纹。如果您的皮肤容易干燥失去光泽,可以用牛奶敷面,连续进行1周,你的面部就会变得娇嫩,充满动人光泽。而具体应该如何用牛奶洗脸呢?而适当地利用牛奶来洗脸,也未尝不是美肤的

炸鱼不粘锅的方法和技巧 如何炸鱼不粘锅

炸鱼不粘锅的方法和技巧——简介炸鱼粘锅是很多人下厨烹饪时的苦恼。炸鱼粘锅有很多原因,但是,方法总比问题多,只要注意学习和总结,还是能找到很多不粘锅的方法和技巧的。炸鱼不粘锅的方法和技巧——方法/步骤炸鱼不粘锅的方法和技巧 1

入定的方法和技巧---打坐入门三要素 如何打坐入定

1.入禅定的条件要离五毒修禅定的方法有很多种。按照我们佛教的禅定修法,不管修哪一种禅定,都要进入初禅、二禅、三禅和四禅这样渐进地修上去。要入定,就要具备一些因缘,就是当时要离五盖。所谓五盖是:昏沉、掉悔、嗔、疑,还有贪欲。当这些

声明:《转载 FileSystemObject的方法和属性 js filesystemobject》为网友過去再見分享!如侵犯到您的合法权益请联系我们删除