Как создать скрипт, который удаляет определенные файлы только в той же папке, в которой сохранен скрипт - PullRequest
0 голосов
/ 17 мая 2019

Я действительно новичок в этом. Но мне было интересно, как создать сценарий .vbs, который при запуске удалит 3 файла из любой папки, в которой сохранен сценарий. Расположение папки будет постоянно меняться, поэтому мне нужно, чтобы он смотрел только там, где сохранен сценарий. Также было бы неплохо, если бы после удаления файлов появилось диалоговое окно с сообщением о завершении задачи.

1 Ответ

0 голосов
/ 28 мая 2019
'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
...