0
我的源文件位置中的所有文件已被複制到 目標文件夾中。 如何複製然後刪除2個文件,只有當我的 datefrom = 12/07/2014和我的 dateto = 12/09/2014。如何在vbscript中只複製和刪除修改日期的文件庫?
- 文件名:修改日期
- 文件1 2014年12月7日
- 文件2 2014年12月9日
- 文件3 2015年1月6日
這是我的代碼。
Dim ObjFso
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim StrSourceLocation
Dim StrDestinationLocation
Dim StrSourceFileName
dim SourceLocation
dim DestinationLocation
dim datefrom, dateto, datectr
datefrom = DateValue("01/01/2015")
dateto = DateValue("01/01/2015")
datefrom = InputBox ("date from: (mm/dd/yyyy)")
dateto = InputBox ("date to: (mm/dd/yyyy)")
StrSourceLocation = InputBox ("source:")
StrDestinationLocation = InputBox ("destination:")
datectr = datefrom
dateto = dateto
intYear=0
intMonth=0
indDay=0
intFileCtr=0
intFileDayCtr=0
SourceLocation = StrSourceLocation + "\*.*"
DestinationLocation = StrDestinationLocation + "\"
Const OverwriteExisting = True
Do Until datectr>dateto
intYear=Year(datectr)
intMonth=Month(datectr)
intDay=Day(datectr)
for each f in objFSO.Getfolder(StrSourceLocation).Files
if Year(f.DateLastModified) = intYear And Month(f.DatelastModified) = intMonth And Day(f.DateLastModified) = intDay Then
objFSO.CopyFile SourceLocation , DestinationLocation, OverwriteExisting
objFSO.DeleteFile(SourceLocation), True
end if
Next
datectr=DateAdd("d", 1, datectr)
datectr = DateValue(datectr)
Loop
我有一系列的文件先生,例如:file1 file2和file3。我想在目標文件夾中僅複製文件1和文件2,並刪除源文件夾中的文件1和文件2。因此file3將保留在源文件夾中,並且file1和file2已被移至目標文件夾。但3個文件已被複制到目標文件夾中,並刪除了源文件夾中的3個文件。 – Jonald 2015-02-09 02:06:54
喜先生。我想我解決了這個問題.. objFSO.CopyFile樓DestinationLocation,OverwriteExisting objFSO.DeleteFile(F),真 – Jonald 2015-02-09 03:16:51