Get the App
SLTechnology News&Howtos  ›  Development  › 

How does vbs implement the script to copy files

Shulou Source: shulou.com Published: 2022-06-03 06:24:06 09月24日 Update

This article will explain in detail the script about how to copy files in vbs. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

The copy code is as follows:

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)

After the recent need to write the following code, you can determine whether the file is updated and the file size is larger.

The copy code is as follows:

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

Here's a more functional code:

The copy code is as follows:

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", 8Jing true)

F.writeline FormatDateTime (Now (), 4) & "\" & cell & "\" & computername

F.close

'* calculate the local FORMAT****

'Getformat

'*

'There is a loop to compare log update dates

Do while (1)

If (fsoG.FileExists (indexPath)) Then

'indicate the last update time

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 ("15:00:00")) and Hour (FormatDateTime (Now (), 4)) = Hour (TimeValue ("7:00:00")) and Hour (FormatDateTime (Now (), 4))

Tags: Files code scripts folders more articles updates features good practical successful two number location content name size instance object copy Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei macOS MySQL Shulou Information Docker