麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > VBScript > 正文

vbs復制文件的腳本

2020-07-26 11:57:17
字體:
來源:轉載
供稿:網友

復制代碼 代碼如下:

parentfolder = "c:/"
sourcefile = "c:/windows/log.log"
targetfolder = parentfolder & date & "/"
set objshell = createobject("shell.application")
set objfolder = objshell.namespace(parentfolder)
objfolder.newfolder date
set so=createobject("scripting.filesystemobject")
so.getfile(sourcefile).copy(targetfolder)


經過最近的需要寫出了如下代碼,可以判斷文件是否更新并且文件大小更大

復制代碼 代碼如下:

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
set fn2=fso.GetFile("c:/index2.htm")
flsize2=fn2.size
fldate2=fn2.datelastmodified
set fn=fso.GetFile("c:/index.htm")
flsize1=fn.size
fldate1=fn.datelastmodified
If fso.FileExists("c:/index2.htm") and flsize2>50000 and fldate2>fldate1 Then
fso.getfile("c:/index2.htm").copy("c:/index.htm")
if err.number=0 then WriteHistory "成功"&now(),"log.txt"
end if

Sub WriteHistory(hisChars, path)
  Const ForReading = 1, ForAppending = 8
  Dim fso, f
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set f = fso.OpenTextFile(path, ForAppending, True)
  f.WriteLine hisChars
  f.Close
End Sub



下面來個功能更多的代碼:

復制代碼 代碼如下:

WScript.Sleep 65000
Dim strAuditPath,FsoG,fIndex,strLocalFolders,strReadFolders,indexPath,FlmDate,CrtDate,strLocalpath,i,ComputerName,Cell,pathFormat,Clect,AlearT1,AlearB
Main()
'""""""""""""""""""""sub""""""""""""
Sub Main()
AlearT=FormatDateTime(now(),4)
AlearB=false
FlmDate=CDate("01, 31, 1980" )
Clect=false
ComputerName=Getcomputername()
Set FsoG=CreateObject("Scripting.FileSystemObject")
GetSetting
'pathFormat=Left(strLocalpath,Len(strLocalpath)-8) & "Labels"
indexPath=strAuditPath & "Index.txt"
set f=FSOG.OPENTEXTFILE(GetAbPath(strAuditPath) & "logo history.txt",8,true)
f.writeline FormatDateTime(Now(),4) & "/" & cell & "/" & computername
f.close
'***************計算本地FORMAT****************************************************************************
' Getformat
'**************************************************************************************************************
'在這里一個循環比較日志更新日期
do while(1)
   If (fsoG.FileExists(indexPath)) Then
    '指出最近更新時間
   set fIndex=fsoG.GetFile(indexPath)
   CrtDate=fIndex.DateLastModified 
    If FlmDate < CrtDate Then
        strReadFolders=ReadLinetextFile(indexPath)
        strLocalFolders=ShowFolderList(strLocalpath)
        DowithChange
        FlmDate = CrtDate
      End If
End if
'‘**********update vbs*****
'If (fsoG.FileExists(getAbpath(strAuditPath) & "pe.vbs")) Then
'fsog.CopyFile getAbpath(strAuditPath) & "pe.vbs",GetAbpath(GetCPath) & "pe.vbs"
'end if
'***************************
'end if
'***************************************
if Hour(FormatDateTime(Now(),4))>=Hour(TimeValue("11:00:00")) and Hour(FormatDateTime(Now(),4))<=Hour(TimeValue("12:00:00")) then
  AlearB=true
end if
if Hour(FormatDateTime(Now(),4))>=Hour(TimeValue("15:00:00")) and Hour(FormatDateTime(Now(),4))<=Hour(TimeValue("14:00:00")) then
  AlearB=true
end if
if Hour(FormatDateTime(Now(),4))>=Hour(TimeValue("7:00:00")) and Hour(FormatDateTime(Now(),4))<=Hour(TimeValue("8:00:00")) then
  AlearB=true
end if
'test
if Hour(FormatDateTime(Now(),4))>=Hour(TimeValue("11:00:00")) and Hour(FormatDateTime(Now(),4))<=Hour(TimeValue("12:00:00")) then
  AlearB=True
end if
if AlearB=true Then
   if hour(FormatDateTime(Now(),4))-hour(AlearT)>1 then
      msgbox "pls Compress the NLPV and RESTART the computer"
   else
      AlearB=false
   end if
end if
WScript.Sleep 10000
Loop
End Sub
Sub Getformat()
strFormats=ShowFilesList(pathFormat)
  Const ForReading = 1, ForWriting = 2
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set f = fso.OpenTextFile(GetAbPath(strAuditPath) & CELL & " " & ComputerName  & ".txt", ForWriting, True)
for i=0 to UBound(strFormats)
f.WriteLine  left(strFormats(i),len(strFormats(i))-4)
next
f.WriteLine cell
f.WriteLine ComputerName
'
  f.Close
clect =true
End sub
Function ShowFilesList(folderspec)
   Dim fso, f, f1, s(), sf,i
   i=0
   redim s(i)
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.GetFolder(folderspec)
    Set fc = f.Files
    For Each f1 in fc
      redim Preserve s(i)
      s(i)= f1.name
      i=i+1
   Next
ShowFilesList=s
End Function
Function ShowFolderList(folderspec)
   Dim fso, f, f1, s(), sf,i
   i=0
   redim s(i)
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.GetFolder(folderspec)
   Set sf = f.SubFolders
   For Each f1 in sf
      redim Preserve s(i)
      s(i)= f1.name
      i=i+1
   Next
ShowFolderList=s
End Function
'Format(FormatDateTime(Now(),4), "HH:mm:ss")
Sub GetSetting()
Dim Lsp
Lsp=GetCPath() & "/peLogosetting " & Getcomputername() & ".txt"
If (Not fsoG.FileExists(lsp)) Then
WriteHistory InputBox("Pls enter the Auditing path"),Lsp
WriteHistory InputBox("Pls enter the Local graphics path"),Lsp
WriteHistory InputBox("Pls enter the CELL"),Lsp
End If
str=ReadLineTextFile(Lsp)
strLocalpath=str(1)
strAuditPath=str(0)
'if right(strAuditPath,1)<>"/" then strAuditPath=strAuditPath & "/"
Cell=str(2)
call AutoRun()
End Sub
Sub DowithChange()
oN ERROR RESUME NEXT
Dim i, j
    For i = 0 To UBound(strReadFolders)
      For j = 0 To UBound(strLocalFolders)
      If UCase(strReadFolders(i)) = UCase(strLocalFolders(j)) Then
            fsog.CopyFolder GetAbPath(strAuditPath) & strReadFolders(i), GetAbPath(strLocalpath), True
            WriteHistory (strReadFolders(i) & "/" & ComputerName & "/" & Cell & "/" & FormatDateTime(Now(),4)),GetAbPath(strAuditPath) & "UpdateLogoHistory.txt"
     End If
      Next
    Next
End Sub
Sub WriteHistory(hisChars, path)
  Const ForReading = 1, ForAppending = 8
  Dim fso, f
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set f = fso.OpenTextFile(path, ForAppending, True)
  f.WriteLine hisChars
  f.Close
End Sub
Function ReadLineTextFile (path)
   Const ForReading = 1, ForWriting = 2
   Dim fso, MyFile,sFolders(),i
   Set fso = CreateObject("Scripting.FileSystemObject")
   i=0
   redim sfolders(i)
   Set MyFile = fso.OpenTextFile(path, ForReading)
   Do While MyFile.AtEndOfLine <> True
    redim Preserve sFolders(i)
    sFolders(i) = MYfile.ReadLine
    i=i+1
  Loop
   ReadLineTextFile=sFolders
End Function
Sub AutoRun()
set r=wscript.createobject("wscript.shell")
yuan = WScript.ScriptFullName
r.RegWrite "HKEY_CURRENT_USER/SOFTWARE/Microsoft/Windows/CurrentVersion/RunOnce/PeLogoUpdate",yuan
end sub
Function GetAbPath(path)
If Right(path, 1) <> "/" Then
GetAbPath = path & "/"
Exit Function
end if
GetAbPath = path
End Function
Function Getcomputername()
Dim a
Set a = CreateObject("Wscript.Network")
Getcomputername= a.ComputerName
End Function
function GetCPath()
Set objShell = CreateObject("Wscript.Shell")
strPath = Wscript.ScriptFullName
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(strPath)
Getcpath = objFSO.GetParentFolderName(objFile)
end Function


vbs復制文件夾

需要實現一個復制文件夾的功能,網上找到相關代碼,并做了改進,vbs腳本如下

復制代碼 代碼如下:

Dim fso, CopyCount
Set fso = CreateObject("Scripting.FileSystemObject")

CopyCount = CopyCount + XCopy(fso, "./1", "./2", True)
MsgBox "拷貝了" & CopyCount & "個文件!"

'********************************************************************
'* Function :     XCopy
'*
'* Purpose:  復制文件和目錄樹。
'*
'* Input:    fso            FileSystemObject 對象實例
'*           source         指定要復制的文件。
'*           destination    指定新文件的位置和/或名稱。
'*           overwrite      是否覆蓋已存在文件。 Ture 覆蓋, False 跳過
'*
'* Output:   返回復制的文件個數
'*
'********************************************************************
Function XCopy(fso, source, destination, overwrite)
    Dim s, d, f, l, CopyCount
    Set s = fso.GetFolder(source)

    If Not fso.FolderExists(destination) Then
        fso.CreateFolder destination
    End If
    Set d = fso.GetFolder(destination)

    CopyCount = 0
    For Each f In s.Files
        l = d.Path & "/" & f.Name
        If Not fso.FileExists(l) Or overwrite Then
            If fso.FileExists(l) Then
                fso.DeleteFile l, True
            End If
            f.Copy l, True
            CopyCount = CopyCount + 1
        End If
    Next

    For Each f In s.SubFolders
        CopyCount = CopyCount + XCopy(fso, f.Path, d.Path & "/" & f.Name, overwrite)
    Next

    XCopy = CopyCount
End Function

在腳本文件路徑建立一個文件夾,取名1,放入兩個文件,運行程序結果如下

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 日日草夜夜草 | 在线成人av观看 | 亚洲日本欧美 | 一级国产航空美女毛片内谢 | 羞羞视频免费观看网站 | 国产精品.com| 在线播放黄色网址 | 97zyz成人免费视频 | 欧美wwwsss9999| 黄色片快播 | pornoⅹxxxxhd麻豆 | 免费一级a毛片免费观看 | 九九视屏| 日本视频在线免费观看 | 13一14毛片免费看 | 国产做爰全免费的视频黑人 | 精品国产一级毛片 | 国产好片无限资源 | 国产乱淫av | 久久蜜桃香蕉精品一区二区三区 | 欧美人xx| 免费看真人a一级毛片 | 日本a级免费 | 日本最新免费二区三区 | 国产精品69页 | 精品久久久久久久久久久久久 | 99在线免费观看视频 | 999插插插 | 欧美hdfree性xxxx | 欧美成年私人网站 | 精品一区二区在线观看视频 | 在线看小早川怜子av | 91短视频在线| 欧美精品一区二区三区久久久 | 一区二区三区欧美在线观看 | 国产毛片网站 | 午夜久久久精品一区二区三区 | 久久草在线视频国产 | 国产一区二区精品免费 | 国产精品99久久免费观看 | 羞羞视频免费视频欧美 |