Delete extensionless files which names end with '_C' string [duplicate]

半城伤御伤魂 提交于 2020-05-15 19:42:04

问题


I have a batch code which cleans files which are older than 15 days. But I want to only delete files that end with '_C' and they have no extension.

Here is my code:

SET mypath=%cd%/downloads 

ForFiles /p %mypath% /d -15 /c "cmd /c For /R %%A in (*_C.*) Do (del /q @fname)

Here are my files:

File Name: ---------Date:

A_C_123_C ------ 18.02.2019

A_C_456_C ------ 01.01.2018

A_C_789_C ------ 01.01.2018

Testfile------------- 01.01.2018

tmp.txt ------------- 01.01.2018

When I execute the code, it cleans Testfile also. I just want to delete extensionless files that end with '_C' and older than 15 days.

What should I do?


回答1:


You do not require incorporating the for loop into the forfiles command. forfiles has it's own search switch /s

You specifically mention you want to only do files ending with _C with no extension, but you added *_C.* which in fact means anything before _C with a dot and anything after the dot. You really just need:

@forfiles /p %mypath% /d -15 /s /m *_C /c "cmd /c If @IsDir==FALSE del @path"


来源:https://stackoverflow.com/questions/60276077/delete-extensionless-files-which-names-end-with-c-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!