简体   繁体   English

Windows 提示比较和删除文件

[英]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]因此,对于以下列表,应仅删除这些文件:[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:列出所有.ifc文件,过滤(排除) _optimized文件,其余检查_optimized文件是否存在,如果存在,则删除该文件:

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.检查目录中的ifc文件列表,在ned处不包含“_Optimized.ifc”,直接检查是否存在带有“_Optimized.ifc”的文件,如果存在,将其删除。

You can do this on the cMD CLI Directly with:您可以直接在 cMD CLI 上执行此操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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