我想实现这样的程序:获取某路径下所有.txt类型文件的创建日期,如果创建日期与系统当前日期相同,则移动该.txt文件到制定文件夹下。
我的代码是这样,我看没有问题,可是为什么总说“实时错误53,找不到文件”呢?
Private Sub Command1_Click()
Dim path1 As String, path2 As String
Dim today, FileTime1 As string
Dim hc1 As String
path1 = "d:\check"
path2 = "e:\下载"
hc1 = "hc"
today = Format(Date, mmdd)
Dim ifile1 , ifile2 As String
ifile1 = path1 & hc1 & today & ".txt"
ifile2 = path2 & hc1 & today & ".txt"
FileTime1 = Format(FileDateTime("ifile1"), mmdd)
If FileTime1 = today Then
Name "ifile1" As "ifile2"
End If
End Sub
我的代码是这样,我看没有问题,可是为什么总说“实时错误53,找不到文件”呢?
Private Sub Command1_Click()
Dim path1 As String, path2 As String
Dim today, FileTime1 As string
Dim hc1 As String
path1 = "d:\check"
path2 = "e:\下载"
hc1 = "hc"
today = Format(Date, mmdd)
Dim ifile1 , ifile2 As String
ifile1 = path1 & hc1 & today & ".txt"
ifile2 = path2 & hc1 & today & ".txt"
FileTime1 = Format(FileDateTime("ifile1"), mmdd)
If FileTime1 = today Then
Name "ifile1" As "ifile2"
End If
End Sub
(1)today = Format(Date, mmdd) 应为today = Format(Date, "mmdd")(2)path1 = "d:\check"
path2 = "e:\下载"
hc1 = "hc"
ifile1 = path1 & hc1 & today & ".txt"
那么ifile1就是 "d:\checkhc0104.txt"
d:\下有checkhc0104.txt?有吗?(3)Name "ifile1" As "ifile2" 是重命名文件而不是移动文件.
如果ifile1表示d:\check\hc0104.txt,ifile2表示e:\下载\hc0104.txt,那么用复制语句
copyfile ifile1,ifile2 可以实现文件的拷贝吗?
谢谢了
Private Sub Command1_Click()
Dim path1 As String, path2 As String
Dim today, FileTime1 As String
Dim hc1 As String
path1 = "d:\check"
path2 = "e:\下载"
hc1 = "\hc"
today = Format(Date, "mmdd")
Dim ifile1, ifile2 As String
ifile1 = path1 & hc1 & today & ".txt"
ifile2 = path2 & hc1 & today & ".txt"
FileTime1 = Format(FileDateTime(ifile1), "mmdd")
If FileTime1 = today Then
FileCopy ifile1, ifile2
End If
End Sub
就可以实现了!太好了!结贴了!