脚本 >在目录中搜索多个文件名,然后将其删除 [英] Script > Search directory for multiple file names and then delete them

查看:28
本文介绍了脚本 >在目录中搜索多个文件名,然后将其删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一个脚本来删除多个文件.我已经能够编写一个在目录中搜索一个文件名然后将其删除的程序,但我需要能够一次指定多个文件名并在找到时删除所有文件名.应该注意的是,我并不是要搜索重复的文件名.现在,每次我想搜索一个文件以删除它时,我都必须编辑脚本,我必须每天多次执行此操作,一次处理十几个左右的文件.....文件名从来都不是相同的;一旦使用,它们将永远不会再次使用.

I need to write a script for deleting multiple files. I have been able to write one that searches a directory for one file name and then deletes it but I need the ability to specify more than one file name at a time and delete all of them if found. It should be noted that I am not trying to search for duplicate file names. Right now I have to edit the script each time I want to search for a file to delete it, I have to do this several times per day with a dozen or so files at a time.....the file names are never the same; once used they will never be used again.

这是我想要实现的目标的示例.

Here is an example of what I'd like to achieve.

在 C:/junk/log/中搜索ff12345a.txt"和hg76930b.dr1"和890379.rt"然后全部删除.

Search C:/junk/log/ for "ff12345a.txt" and "hg76930b.dr1" and "890379.rt" then delete all.

现在我正试图通过一个 bat 文件来做到这一点,但最终拥有一个具有 GUI 的 vb 程序会很酷,允许我指定我想要搜索的多个文件,而不是每次都编辑脚本.

For now I am attempting to do this through a bat file but eventually it would be cool to have a vb program that has a GUI allowing me to specify multiple files I want to search for rather than editing the script each time.

提前致谢!

推荐答案

    ' make a reference to a directory
    Dim di As New IO.DirectoryInfo("c:\")
    Dim diar1 As IO.FileInfo() = di.GetFiles()
    Dim dra As IO.FileInfo

   'list the names of all files in the specified directory
    For Each dra In diar1
   'Do what you want with dra / Use your delete code here
        ListBox1.Items.Add(dra)
    Next

要过滤搜索,将 di.GetFiles() 更改为 di.GetFiles(.extionion")

To filter search change di.GetFiles() to di.GetFiles(".extionsion")

这篇关于脚本 >在目录中搜索多个文件名,然后将其删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆