批量删除文件夹中的所有文件与路径中的通配符 [英] Batch to delete all files in a folder with a wildcard in the path

查看:339
本文介绍了批量删除文件夹中的所有文件与路径中的通配符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我想要做的就是进入以下目录中的每个文件夹

 C:\\ Documents和Settings \\

和在它的每一个文件夹中,无论名字,检查此路径存在

 C:\\ Documents和Settings \\ * \\本地设置\\应用数据\\ CSMRpt \\

如果它存在,然后删除该董事里面的所有TXT文件,如果路径不存在,那么什么也不做,并移动到下一个文件夹里面的C:\\ Documents和Settings \\

这是我想出迄今:

 设置PATH =\\本地设置\\应用数据\\ CSMRpt \\
设置FILETYPE =* .TXT
针对/ D %%克(C:\\ Documents和Settings \\ *)存在%%摹%PATH%转到pathexists办
:pathexists
德尔%%摹%PATH %% FILETYPE%


解决方案

试试这个。

 关闭@echo
SETLOCAL
设置CWD =%CD%
集P =本地设置\\应用数据\\ CSMRpt
CD / DC:\\ Documents和Settings \\
针对/ D %%我在(*)做(
    如果存在%% I \\%P%\\(
        PUSHD%% I \\%P%\\
        DEL / Q * .TXT
        POPD
    )

::(回原来的目录改变)
CD / D%CWD%

So what I'm trying to do is go into every folder in the following directory

"C:\Documents and Settings\"

and for every folder in it, regardless of the name, check if this path exists

"C:\Documents and Settings\*\Local Settings\Application Data\CSMRpt\"

if it exists then delete all txt files inside that director, if the path doesn't exists then do nothing and move on to the next folder inside "C:\Documents and Settings\"

This is what I came up with so far:

set PATH = "\Local Settings\Application Data\CSMRpt\"
set FILETYPE = "*.txt"
for /d %%g in ("C:\Documents and Settings\*") do if exist %%g%PATH% goto pathexists
:pathexists
del %%g%PATH%%FILETYPE%

解决方案

Try this.

@echo off
setlocal
set cwd=%CD%
set p=Local Settings\Application Data\CSMRpt
cd /d "c:\Documents and Settings\"
for /d %%I in (*) do (
    if exist "%%I\%p%\" (
        pushd "%%I\%p%\"
        del /q *.txt
        popd
    )
)
:: (change back to original directory)
cd /d "%cwd%"

这篇关于批量删除文件夹中的所有文件与路径中的通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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