简体   繁体   English

如何创建一个脚本,仅在保存脚本的同一文件夹中删除某些文件

[英]How to create a script that deletes certain files in only the same folder the script is saved

I'm really new to this. 我真的很陌生。 But I was wondering how to create a .vbs script that, when ran, will delete 3 files out of whatever folder the script is saved in. The folder location will change constantly so I need it to look only wherever the script is saved. 但我想知道如何创建一个.vbs脚本,当运行时,将从保存脚本的任何文件夹中删除3个文件。文件夹位置将不断变化,所以我只需要查看脚本保存的位置。 It would also be nice if after it deleted the files, a dialog box would pop up stating that the task is finished. 如果删除文件后会弹出一个对话框,说明任务已完成,这也很好。

'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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM