删除名称以"_C"结尾的无扩展名文件 [英] Delete extensionless files which names end with '_C' string

查看:116
本文介绍了删除名称以"_C"结尾的无扩展名文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个批处理代码,可以清除早于15天的文件.但是我只想删除以'_C'结尾且没有扩展名的文件.

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.

这是我的代码:

SET mypath=%cd%/downloads 

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

这是我的文件:

文件名:---------日期:

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

A_C_123_C ------ 18.02.2019

A_C_123_C ------ 18.02.2019

A_C_456_C ------ 2018年1月1日

A_C_456_C ------ 01.01.2018

A_C_789_C ------ 2018年1月1日

A_C_789_C ------ 01.01.2018

测试文件 ------------- 2018年1月1日

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

tmp.txt ------------- 2018年1月1日

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

执行代码时,它也会同时清理 Testfile .我只想删除以'_C'结尾且超过15天的无扩展名文件.

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.

我该怎么办?

推荐答案

您不需要将for循环合并到forfiles命令中. forfiles有自己的搜索开关/s

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

您特别提到您只想处理以_C结尾且没有扩展名的文件,但是您添加了*_C.*实际上意味着_C之前带有点的任何内容以及该点之后的任何内容.您真的只需要:

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"

这篇关于删除名称以"_C"结尾的无扩展名文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆