vbs復(fù)制文件夾的實(shí)現(xiàn)代碼
來源:易賢網(wǎng) 閱讀:1207 次 日期:2016-06-22 09:11:42
溫馨提示:易賢網(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 跳過

'*

'* 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)查看腳本欄目
易賢網(wǎng)手機(jī)網(wǎng)站地址:vbs復(fù)制文件夾的實(shí)現(xiàn)代碼
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn)

版權(quán)所有:易賢網(wǎng)