【问题标题】:How to create a script that deletes certain files in only the same folder the script is saved如何创建一个脚本,该脚本仅删除保存脚本的同一文件夹中的某些文件
【发布时间】:2019-10-04 21:56:47
【问题描述】:

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

【问题讨论】:

    标签: adsutil.vbs


    【解决方案1】:
    '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
    

    【讨论】:

    • 这正是我所需要的。谢谢!
    猜你喜欢
    • 2023-03-23
    • 1970-01-01
    • 2013-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多