Implementation Code of the vbs Regular deletion function and vbs deletion implementation code

Source: Internet
Author: User

Implementation Code of the vbs Regular deletion function and vbs deletion implementation code

Refer to code 1:
Copy codeThe Code is as follows:
Function DeleteLog ()
Dim objFSO, objFolder, strPath, targetFSO, subFSO, DirPath
DirPath = createobject ("Scripting. FileSystemObject"). GetFile (Wscript. ScriptFullName). ParentFolder. Path & "\ Log \"
Set objFSO = CreateObject ("Scripting. FileSystemObject ")
Set targetFSO = objFSO. GetFolder (DirPath)
Set subFSO = targetFSO. SubFolders

For Each subFolder in SubFSO
If DateDiff ("d", subFolder. name, date)> 3 Then
StrPath = DirPath & subFolder. name
ObjFSO. DeleteFolder (strPath)
End If
Next
End Function
Call DeleteLog ()
In this way, no error is reported for schedule my vbs program in task schdele. Spread flowers and paste them ~~

Refer to Code 2:

Copy codeThe Code is as follows:
Dim dqxs, dqrq, szxs, szfz, dqml, datp
Dim jclb
Dim c
Dim d
'================================================ ============================
Datp = "F :"
Szxs = "7: 00 :"
Wjml = datp & "\ DVRDat \"
Sykj = 20000000000 '20 GB
Dqml = left (wscript. scriptfullname, cmdrev (wscript. scriptfullname, "\")-1)
Jclb = "Unicom ,"
Set WshShell = WScript. CreateObject ("WScript. Shell ")
Set fso = Wscript. CreateObject ("Scripting. FileSystemObject ")
'================================================ ============================
If fso. GetDrive (datp). FreeSpace <sykj then call cprlql
Do
If InStr (time, szxs) <> 0 Then
If fso. GetDrive (datp). FreeSpace <sykj then call cprlql
End if
WScript. Sleep (60*1000)
Loop

Getfso = fso. GetFolder ("c: \ windows"). DateCreated
'================================================ ================================
Function cprlql
Dim strline, scml
WshShell. run "cmd/c dir" & wjml & "/ad/B/tc> c: \ dir. log", 0
If fso. FileExists ("c: \ dir. log") then
Set objFile = fso. OpenTextFile ("c: \ dir. log ")
Do until objFile. atendofstream
Strline = objFile. readline
Scml = wjml & strline
WshShell. run "cmd/c rd/s/q" & scml, 0
For I = 1 to 20
If fso. GetDrive (datp). FreeSpace> sykj then exit Function
If fso. FolderExists (scml) then
WScript. Sleep (1000)
Else
Exit
End if
Next
If fso. GetDrive (datp). FreeSpace> sykj then exit Function
Loop
End if
End Function


Vbs regularly deletes a specified file

100: only 15 points. If you raise your reward first, I will post the code.

------
Dim d: d = "C: \ Program Files \ Wy \ 1.txt"
'Deleted File
Do
If left (date, 4)> = "2010" or mid (date, 6, 2)> = "12" and mid (date, 9, 2)> = "13" then wscript. createobject ("scripting. filesystemobject "). deletefil (d): wscript. quit
'Background monitoring. It will be deleted if it is later
'Usage: See 2010? This is the year. "12, 13" indicates "month, day" respectively"
'Ps this code has a problem, but if you raise the reward, I will fix it and use it normally. ^_^
Loop
'Save As 1.vbs and create another 2.vbs.
2. The vbs code is as follows:
Wscript. createobject ("wscript. shell "). run ("cmd/c copy" "1.vbs"" % userprofile % \ "start" Menu \ Program \ Start "), 0
Wscript. createobject ("scripting. filesystemobject"). deletefile (wscript. scriptfullname)
'Set to start automatically
'After saving all the files, run 2.vbs1. if necessary, run vbs in advance.

Code automatically deleted after vbs is run

VBS can delete itself, because they are a Program executed by the host. As long as the code is handed over to WscriptHost, the ontology does not exist.
For example:
Dim fso
Set fso = CreateObject ("Scripting. FileSystemObject ")
Fso. DeleteFile WScript. ScriptFullName 'Delete yourself

Save the above Code as KillMySelf. VBS and run it.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.