问题
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.
Search C:/junk/log/ for "ff12345a.txt" and "hg76930b.dr1" and "890379.rt" then delete all.
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.
Thanks in advance!
回答1:
' 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
To filter search change di.GetFiles() to di.GetFiles(“.extionsion”)
来源:https://stackoverflow.com/questions/27945582/script-search-directory-for-multiple-file-names-and-then-delete-them