Exclude string from wildcard

Les Isaacs

Registered User.
Local time
Today, 19:53
Joined
May 6, 2008
Messages
186
Hi All
I have:
Code:
            Kill "Z:\Client_Reports\" & [websiteID] & "\" & LEFT([Forms]![frm x main]![month name], 3) & "*"
This has been working fine - all the files that meet that criteria are deleted, but now I need the option to exclude a particular file from those to be deleted: the particular file would be identified by having some specific text in its filename. So for example I need to be able to delete all files meeting the criteria EXCEPT any files that have the string "summary" as part of the filename. Can this be done :confused:

Thanks for any help.
Les
 
Not in a single kill or any DOS Command...
You can
1)
Move the summary files to a subfolder, delete the other files, move summary back
2)
Do a dir of the files and loop the files one by one and deside in some VBA if to delete or not.
 
Hi 'namliam'

Many thanks for your reply.
I think your option 2 sounds like the best one for our purpose: but how do I
do a dir of the files and loop the files
Sorry to be a bit clueless :(
 
Somewhat psuedo... but

Code:
Dim Filename as string
filename = dir("Your dir and file mask to search")
Do while Filename <> ""
     debug.print filename 'Writes the filename so you can (double) check them easily
     if instr(1,Filename, "Summary") = 0 then 
         Kill your file
     else
         'do nothing to summary files
     endif
     filename = dir 'get next filename
loop
 
Sorry - I get the logic of what you've suggested, but does this assume that all the potential filenames to be deleted are exactly known? In the case I have, the filenames could be anything that meets the criteria:
Code:
LEFT([Forms]![frm x main]![month name], 3) & "*"
So I can't see how to move to the next file :(

Sudden thought:eek:
Maybe I can just keep re-assigning filename:
Code:
Dim Filename as string
filename = dir("Z:\Client_Reports\" & [websiteID] & "\" & LEFT([Forms]![frm x main]![month name], 3) & "*")
Do while Filename <> ""
     debug.print filename 'Writes the filename so you can (double) check them easily
     if instr(1,Filename, "Summary") = 0 then 
         Kill your file
     else
         'do nothing to summary files
     endif
    filename = dir("Z:\Client_Reports\" & [websiteID] & "\" & LEFT([Forms]![frm x main]![month name], 3) & "*")
loop
Would that be it? I can't try it now, but just maybe .....
 
No, well kindoff, anytime you do Dir("Somefilename") you get a new dir requested as such will always return the same file (if its not deleted)

Dir ... without any filename will fetch the next filename available
 

Users who are viewing this thread

Back
Top Bottom