明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1507|回复: 0

经本人测试通过的一些FSO移植到VBA

[复制链接]
发表于 2012-1-19 11:29:37 | 显示全部楼层 |阅读模式
本帖最后由 crazylsp 于 2012-1-19 11:37 编辑

'查询磁盘信息
Private Sub CommandButton1_Click()
Dim fsoTest As Object
Dim drv1 As Object  'N年前明经老大的专贴中写成了drive,这里提醒一下呵呵
Dim sReturn As String
Set fsoTest = CreateObject("Scripting.FileSystemObject")
Set drv1 = fsoTest.GetDrive("K:\")
sReturn = "Drive " & "K:\" & vbCrLf
sReturn = sReturn & "VolumeName" & drv1.VolumeName & vbCrLf
sReturn = sReturn & "Total Space: " & FormatNumber(drv1.TotalSize / 1024, 0)
sReturn = sReturn & "Kb" & vbCrLf
sReturn = sReturn & "Free Space: " & FormatNumber(drv1.FreeSpace / 1024, 0)
sReturn = sReturn & "Kb" & vbCrLf
sReturn = sReturn & "FileSystem:" & drv1.FileSystem & vbCrLf
MsgBox sReturn
End Sub

'显示保存框
Private Sub CommandButton10_Click()
Dim b As Object
Dim a As String
Set b = commondialog1.showsave
a = richtextbox1.savefile(commondialog1.FileName.trfRTF)
End Sub

'新建文本文件
Private Sub CommandButton12_Click()
Dim a As Object
Dim b As Object
Dim c As String
Set a = CreateObject("Scripting.FileSystemObject")
Set b = a.createtextfile("k:\tt.txt", True)
b.writeline ("my first love")
MsgBox "creat new text!"
b.Close
End Sub

'得到文件时间
Private Sub CommandButton15_Click()
Dim a As Object
Dim b As Object
Dim c As String
Set a = CreateObject("Scripting.FileSystemObject")
Set b = a.getfile("k:\web.txt")
c = b & " " & b.datecreated
MsgBox c
End Sub

'新建文件夹
Private Sub CommandButton2_Click()
Dim a As Object
Dim b As Object
Set a = CreateObject("Scripting.FileSystemObject")
Set b = a.createfolder("k:\new folder")
End Sub

'删除文件或文件夹
Private Sub CommandButton3_Click()
Dim a, b As Object
Set a = CreateObject("Scripting.FileSystemObject")
'Set b = a.getfolder("k:\新建文件夹 (2)")
Set b = a.deletefolder("k:\新建文件夹 (2)")
End Sub

'显示文件夹建立时间
Private Sub CommandButton4_Click()
Dim a As Object
Dim b As Object, c As String
Set a = CreateObject("Scripting.FileSystemObject")
Set b = a.getfolder("k:\工作文章")
c = b.datecreated
MsgBox b & " " & c
End Sub

'移动文件 实际木起作用待大伙改进
Private Sub CommandButton5_Click()
Dim a As Object
Dim b As Object
Set a = CreateObject("Scripting.FileSystemObject")
Set b = a.movefile("k:\batch  plot  dwg.lsp", "k:\txt\batch  plot  dwg.lsp")
End Sub

'复制文件
Private Sub CommandButton6_Click()
Dim a As Object
Dim b As Object
Set a = CreateObject("Scripting.FileSystemObject")
Set b = a.Copyfile("k:\*.txt", "K:\txt\")
End Sub

'复制文件或文件夹
Private Sub CommandButton7_Click()
Dim a As Object
Dim b As Object
Dim c As Object
Set a = CreateObject("Scripting.FileSystemObject")
Set b = a.getfile("k:\txt.lsp")
Set c = b.Copy("k:\中桥\", True)
End Sub

'移动文件夹  实际木起作用待大伙改进
Private Sub CommandButton9_Click()
Dim a As Object
Dim b As Object
Set a = CreateObject("Scripting.FileSystemObject")
Set b = a.movefolder("k:\箱梁文件", "k:\中桥")
End Sub


您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-25 17:35 , Processed in 0.150119 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表