2015-02-08 89 views
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 

回答

0

我不知道你在做什麼。 VBS中的日期很簡單。

If DateValue("01/01/1980") < DateValue("01/01/1990") or DateValue("01/01/1980") > DateValue("01/01/1960") then 

' blah 
End If 

是如何檢查範圍內的日期。

也有類似的DateSerial。日期是過去一天(01/01/100 AD)以來的x天數,時間是一天中的一小部分(下午12點是0.5)。

+0

我有一系列的文件先生,例如:file1 file2和file3。我想在目標文件夾中僅複製文件1和文件2,並刪除源文件夾中的文件1和文件2。因此file3將保留在源文件夾中,並且file1和file2已被移至目標文件夾。但3個文件已被複制到目標文件夾中,並刪除了源文件夾中的3個文件。 – Jonald 2015-02-09 02:06:54

+0

喜先生。我想我解決了這個問題.. objFSO.CopyFile樓DestinationLocation,OverwriteExisting objFSO.DeleteFile(F),真 – Jonald 2015-02-09 03:16:51

相關問題