0

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

4

1 回答 1

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
于 2019-05-28T10:05:40.563 回答