简体   繁体   中英

windows prompt compare and remove files

I have a Command Prompt question, hopefully you can help me out.. I have a file-list in a certain directory where i want to remove only the old files which are optimized. So for the following list only theses files should be removed: [file2.ifc / file5.ifc / mainpart.ifc]

file1.ifc
file2.ifc
file2_optimized.ifc
file3.ifc
file4.ifc
file5.ifc
file5_optimized.ifc
mainpart.ifc
mainpart_optimized.ifc

How can this be achieved?

Thanx in advance,

Loek

List all .ifc files, filter (exclude) the _optimized files and for the rest check if an _optimized file exists and if yes, delete the file:

for /f "delims=" %%a in ('dir /b *.ifc^|findstr /vie "_optimized.ifc"') do (
   if exist "%%~na_optimized%%~xa" del "%%a"
)

Check the List of ifc Files in the directory, that do not contain "_Optimized.ifc" at the ned, and simply check if one with "_Optimized.ifc" DOES exist in the directly, if it does, delete it.

You can do this on the cMD CLI Directly with:

FOR %A IN (
  "C:\Folder\Path\*.ifc"
) DO (
  ECHO=%~nx_FIND /V /I "_Optimized.ifc" && (
    IF EXIST "%~dpnA_Optimized.ifc" (
      DEL /F /Q "%~fA"
    )
  )
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM