vbs復(fù)制文件夾的實(shí)現(xiàn)代碼
來(lái)源:易賢網(wǎng) 閱讀:2772 次 日期:2014-04-23 10:33:07
溫馨提示:易賢網(wǎng)小編為您整理了“vbs復(fù)制文件夾的實(shí)現(xiàn)代碼”,方便廣大網(wǎng)友查閱!

這篇文章主要介紹了vbs復(fù)制文件夾的實(shí)現(xiàn)代碼.

需要實(shí)現(xiàn)一個(gè)復(fù)制文件夾的功能,網(wǎng)上找到相關(guān)代碼,并做了改進(jìn),vbs腳本如下

代碼如下:

Dim fso, CopyCount

Set fso = CreateObject("Scripting.FileSystemObject")

CopyCount = CopyCount + XCopy(fso, ".\1", ".\2", True)

MsgBox "拷貝了" & CopyCount & "個(gè)文件!"

'********************************************************************

'* Function :     XCopy

'*

'* Purpose:  復(fù)制文件和目錄樹。

'*

'* Input:    fso            FileSystemObject 對(duì)象實(shí)例

'*           source         指定要復(fù)制的文件。

'*           destination    指定新文件的位置和/或名稱。

'*           overwrite      是否覆蓋已存在文件。 Ture 覆蓋, False 跳過(guò)

'*

'* Output:   返回復(fù)制的文件個(gè)數(shù)

'*

'********************************************************************

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

在腳本文件路徑建立一個(gè)文件夾,取名1,放入兩個(gè)文件,運(yùn)行程序結(jié)果如下

名單

vbs復(fù)制文件的代碼:

代碼如下:

[code]

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

[/code]

更多信息請(qǐng)查看IT技術(shù)專欄

更多信息請(qǐng)查看腳本欄目
易賢網(wǎng)手機(jī)網(wǎng)站地址:vbs復(fù)制文件夾的實(shí)現(xiàn)代碼
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

2025國(guó)考·省考課程試聽報(bào)名

  • 報(bào)班類型
  • 姓名
  • 手機(jī)號(hào)
  • 驗(yàn)證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
云南網(wǎng)警備案專用圖標(biāo)
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專用圖標(biāo)