如何创建仅删除脚本所在文件夹中的某些文件的脚本

时间:2019-05-17 14:34:00

标签: adsutil.vbs

我真的很陌生。但是我想知道如何创建一个.vbs脚本,该脚本在运行时将从保存脚本的任何文件夹中删除3个文件。文件夹位置将不断变化,因此我需要它仅查看脚本保存的位置。如果删除文件后弹出一个对话框,说明任务已完成,那也很好。

1 个答案:

答案 0 :(得分:0)

'Very simple code where both the vbs file 
'and the files to be deleted are in the same directory.

Set WshShell = WScript.CreateObject("WScript.Shell")

Set fso = CreateObject("Scripting.FileSystemObject")

Route=(fso.GetParentFolderName(WScript.ScriptFullName))&"\"  

' Route =Directory where these files and the vbs file are located


file1 = Route&"Example.txt":ctrol1=" Doesn't exist" ' Example 1

file2 = Route&"Example.pdf":ctrol2=" Doesn't exist" ' Example 2

file3 = Route&"Example.jpg":ctrol3=" Doesn't exist" ' Example 3

' ctrol1, ctrol2. ctrrol3 are variables of control for each file, 
' of entry they leave with that the file to erase does not exist.
' It changes its value when the file exists and has been deleted.


If fso.FileExists(file1) Then fso.DeleteFile(file1) :ctrol1=" deleted"
' if file 1 exists then delete it

If fso.FileExists(file2) Then fso.DeleteFile(file2) :ctrol2=" deleted"
' if file 2 exists then delete it

If fso.FileExists(file3) Then fso.DeleteFile(file3) :ctrol3=" deleted"
' if file 2 exists then delete it


' result of the process. chr(13) is a line break.

Msgbox "The Files: "&chr(13)&chr(13)&file1&ctrol1&chr(13)_
&file2&ctrol2&chr(13)&file3&ctrol3,4096