Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to copy folders with vbs

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "how to copy folders in vbs". In daily operation, I believe many people have doubts about how to copy folders in vbs. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "how to copy folders in vbs". Next, please follow the editor to study!

The code is as follows:

Dim fso, CopyCount

Set fso = CreateObject ("Scripting.FileSystemObject")

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

MsgBox "copied" & CopyCount & "A file!"

'*

'* Function: XCopy

'*

'* Purpose: copy files and directory trees.

'*

'* Input: fso FileSystemObject object instance

'* source specifies the file to copy.

'* destination specifies the location and / or name of the new file.

'* whether overwrite overwrites existing files. Ture override, False skip

'*

'* Output: returns the number of files copied

'*

'*

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

Create a folder in the path of the script file, name it 1, and put in two files. The result of running the program is as follows

Vbs copies the code for the file:

The code is as follows:

[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 "success" & 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]

At this point, the study on "how to copy folders in vbs" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report