以下是文件夹的操作.
****************移动文件夹************************
1、添加引用"microsoft
scripting
runtime"
2、使用方法
Option
Explicit
Private
Sub
Form_Load()
Dim
FileSys
As
New
FileSystemObject
Dim
FolderObj
As
Folder
Set
FileSys
=
CreateObject("scripting.filesystemobject")
FileSys.CopyFile
"c:\ss.txt",
"d:\mm.txt",
True'拷贝文件
FileSys.CopyFolder
"c:\1",
"d:\2",
True'拷贝文件夹
End sub
***************新建文件夹**************************
Dim
fso
As
New
FileSystemObject,
fdr
As
Folder,fdrPath
as
String
fdrPath="C:\newfolder"
fdr
=
fso.CreateFolder(fdrPath)
***************重命名文件夹***************
Dim
aa
As
New
Scripting.FileSystemObject
aa.MoveFolder
"c:\1",
"c:\2"
**************************************************
fileName = "c:\dzh\export\1001A1AA.XLS"
If Dir(fileName) = "" Then
'文件存在
sWenJJ_MingC = "000001"
Else
sWenJJ_MingC = "000002"
End If
pathName = "c:\dzh\dataFX\" & sWenJJ_MingC
fso.MoveFolder "c:\dzh\export", pathName
'文件夹剪切,重命名
fso.CreateFolder "c:\dzh\export"
'新建文件夹
使用Dir后再使用fso.MoveFolder会产生错误!
If fso.FileExists(fileName) = False Then
sWenJJ_MingC = "000001"
Else
sWenJJ_MingC = "000002"
End If
改为以上代码判断文件是否存在即可解决问题。
另外,若dir使用很多修改不便的话可换另一方法,
先新建一个文件夹mkdir(),
再将原文件夹里面的东西全考到新文件夹即可。