用VB实现重命名、拷贝文件夹及文件

用VB实现重命名、拷贝文件夹及文件


Private Sub commandButton1_Click()

'声明文件夹名和路径
Dim FileName, Path As String, EmptySheet As String
'Path = "D:\上报"
Path = InputBox("请输入" & Chr(34) & "成绩" & Chr(34) & "文件夹的路径,格式如" & Chr(34) & "D:\成绩" & Chr(34))
FileName = Path & "\上学期"
EmptySheet = Path & "\学期初始化"
'MsgBox FileName
If Dir(FileName, vbDirectory) <> "" Then
'MsgBox "文件夹存在"
'获取系统当前时间
'Dim dd As Date
'dd = Now
'MsgBox Format(dd, "yyyymm")

Dim myTime As String
myTime = InputBox("请输入当前时间,格式如" & Chr(34) & "201811" & Chr(34))
If myTime = "" Then
MsgBox "当前时间不能为空!否则不能重命名当期文件夹"
Else:
Name FileName As Path & "\" & myTime
End If
End If
'判断文件夹是否存在
If Dir(FileName, vbDirectory) = "" Then
'创建文件夹
MkDir (FileName)

'MsgBox ("创建完毕")
Else: MsgBox ("文件夹已在")
End If
'复制空表到当期
Set Fso = CreateObject("Scripting.FileSystemObject")
'拷贝文件夹
Fso.copyfolder EmptySheet, FileName
'Fso.copyfile EmptySheet&"c:\*.*", "d:\" '拷贝文件
'FileSystemObject.copyfolder EmptySheet, FileName, 1
MsgBox ("操作成功!")
End Sub

猜你喜欢

转载自blog.csdn.net/LFfootprint/article/details/84894170
今日推荐