WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: morenos1 on January 07, 2015, 02:28:31 PM

Title: Performing files deletion with exclusion.
Post by: morenos1 on January 07, 2015, 02:28:31 PM
Any quick way to delete  files while excluding some?.

Thanks....
Title: Re: Performing files deletion with exclusion.
Post by: JTaylor on January 07, 2015, 05:52:44 PM
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
Title: Re: Performing files deletion with exclusion.
Post by: morenos1 on January 08, 2015, 07:09:24 AM
Delete everything in a folder structure minus a specific type of file ....
Title: Re: Performing files deletion with exclusion.
Post by: JTaylor on January 08, 2015, 08:24:59 AM
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
Title: Re: Performing files deletion with exclusion.
Post by: td on January 08, 2015, 10:58:05 AM
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')
Title: Re: Performing files deletion with exclusion.
Post by: morenos1 on January 08, 2015, 12:20:15 PM
Thank You. This will work  ......