How to delete *.* excluding some extensions?

前端 未结 6 2170
夕颜
夕颜 2020-12-10 05:46

I\'m trying to make a batch file on Windows for deleting all the files in the current directory but excluding 4 file extensions (log, sdb, SDK, bat).

I have tried th

6条回答
  •  不知归路
    2020-12-10 06:24

    If ROBOCOPY is available to you:

    @ECHO OFF
    MKDIR temporary_pit
    ROBOCOPY . temporary_pit /XF *.sdb *.sbk *.log *.bat /MOV >NUL
    RMDIR /S /Q temporary_pit
    

    That is, you are creating a temporary subdirectory, moving the files that are to be deleted to it (which is fast because, as the destination directory is on the same drive, only file names are relocated, not the files' contents), then deleting the subdirectory.

提交回复
热议问题