How to delete specific files in a folder with Access VBA

jimsabyss

New member
Local time
Today, 15:00
Joined
Nov 2, 2015
Messages
1
I'm looking to delete all files in a folder (using VBA), except 3 specific ones. All files in this folder are .csv files, and all of the file names are different. Let's call the 3 files I do NOT want to delete "Jim.csv", "Chuck.csv", and "Matt.csv". Is there a way to delete all files EXCEPT the ones you specify?
 
Nope. Specify which to delete one by one then. As a silly patch you could temporarily rename the exceptions.
 
Disagree. You can delete all files except specific ones.

Code:
dim str as string
   
str = dir("C:\temp\*.*")
do while str <> ""
   if not (str = "mike.csv" or str = "chuck.csv" or str = "matt.csv") then
         kill str
    end if
    str = dir
loop
Or have I misunderstood the requirement?
 

Users who are viewing this thread

Back
Top Bottom