vbs复制文件夹的实现代码

2022-05-20 03:20:21   第一文档网     [ 字体: ] [ 阅读: ] [ 文档下载 ]
说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。下载word有问题请添加QQ:admin处理,感谢您的支持与谅解。点击这里给我发消息

#第一文档网# 导语】以下是®第一文档网的小编为您整理的《vbs复制文件夹的实现代码》,欢迎阅读!
文件夹,复制,代码,实现,vbs





这篇文章主要介绍了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,放入两个文件,运行程序结果如下 vbs复制文件的代码: 代码如下: [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]


本文来源:https://www.dywdw.cn/386f01a30640be1e650e52ea551810a6f424c85e.html

相关推荐
推荐阅读