Performing files deletion with exclusion.

Started by morenos1, January 07, 2015, 02:28:31 PM

Previous topic - Next topic

morenos1

Any quick way to delete  files while excluding some?.

Thanks....

JTaylor

Far to little info to give a good answer...there is, of course, FileDelete().  You might take a look at the FileSearch Extender.   Without knowing what you want to do can't offer much more.


Jim

morenos1

Delete everything in a folder structure minus a specific type of file ....

JTaylor

If you are needing to traverse directories then the FileSearch Extender is probably your best bet.  You can retrieve a list of the files, excluding the ones you want to exclude, and then delete them.  If only specific file types reside within the structure then you could work with directories and file types, still using the Extender, perhaps but if that is an unknown then file by file should do the trick.

Jim

td

Quote from: morenos1 on January 08, 2015, 07:09:24 AM
Delete everything in a folder structure minus a specific type of file ....

Code (winbatch) Select
AddExtender("wwfaf44i.dll")
strPath = "c:\projects\foldersearch\test\Clean"
lExclude = 'log|wbt'    ; Don't delete files with these extensions.
nCnt    = 0
fsHandle = fafOpen(strpath, "*.*", 16) ; 16 = do sub directories.
While @TRUE
   strFound = fafFind(fsHandle)
   If strFound == "" Then Break
   if !ItemLocate(FileExtension(strfound),lEcxlude, '|')
      nMode = ErrorMode(@Off)
      FileDelete(strFound)
      ErrorMode(nMode)
      if LastError() then Pause("Delete Failed", strFound)
      else nCnt+=1
   endif
EndWhile
:cancel
fafClose(fsHandle)
Message('Done', nCnt:' file(s) deleted')
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

morenos1